无法在Google容器优化操作系统上运行可执行shell脚本

Mat*_*son 4 google-cloud-platform google-container-os

在任何其他Linux发行版上,我可以使用shebang创建一个文件并运行shell脚本,如下所示:

$ chmod +x test.sh
$ ./test.sh Johnny
hello Johnny
Run Code Online (Sandbox Code Playgroud)

但是在谷歌云平台容器优化操作系统上,我得到了 -bash: ./test.sh: Permission denied

如果我加前缀,sh例如sh test.sh Johnny它将起作用.我怎样才能让它正常工作?

$ cat test.sh
#!/usr/bin/env sh

echo "Hello $@"

matt@rancher-4mmm /tmp/matt $ chmod +x test.sh 
matt@rancher-4mmm /tmp/matt $ sh ./test.sh matt
Hello matt

matt@rancher-4mmm /tmp/matt $ ./test.sh matt
-bash: ./test.sh: Permission denied
matt@rancher-4mmm /tmp/matt $ ls -la
total 4
drwxr-xr-x  2 matt matt  60 Feb 28 20:00 .
drwxrwxrwt 14 root root 280 Feb 28 19:59 ..
-rwxr-xr-x  1 matt matt  35 Feb 28 20:00 test.sh
Run Code Online (Sandbox Code Playgroud)

小智 9

COS节点上的大多数文件系统都装有"noexec"标志,因此您无法从它们执行二进制文件.

一些解决方法:

  • 对于脚本,使用脚本作为参数调用解释器,"bash /path/script.sh","python /path/app.py"
  • 在/ mnt/disks下安装额外的数据磁盘.您可以在没有"noexec"标志的情况下安装它.使用startup-script在引导时挂载.


N S*_*ngh 5

容器优化的操作系统使用“ noexec”标志挂载文件系统,除了“在可写位置中,只有/ var / lib / docker和/ var / lib / cloud被挂载为”可执行文件”(即,没有noexec挂载标志)。 ” [1]。您可以使用以下命令进行验证:

mount | grep noexec
Run Code Online (Sandbox Code Playgroud)

有关容器优化的OS(COS)文件系统的布局的更多信息,请参阅文档。'noexec'选项不允许在已挂载的文件系统上直接执行任何二进制文件。这是因为默认情况下在COS上实施了安全锁定。

  • 真的很烂_) (2认同)