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

Google cloud platform 无法在Google容器优化操作系统上运行可执行shell脚本,google-cloud-platform,google-container-os,Google Cloud Platform,Google Container Os,在任何其他linux发行版上,我都可以使用shebang创建一个文件并运行shell脚本,如下所示: $ chmod +x test.sh $ ./test.sh Johnny hello Johnny 但在谷歌云平台容器优化操作系统上,我得到了-bash:./test.sh:权限被拒绝 如果我用sh作为前缀,例如sh test.sh Johnny它会工作。我怎样才能让它正常工作 $ cat test.sh #!/usr/bin/env sh echo "Hello $@" matt@ra

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

$ chmod +x test.sh
$ ./test.sh Johnny
hello Johnny
但在谷歌云平台容器优化操作系统上,我得到了
-bash:./test.sh:权限被拒绝

如果我用
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

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

mount | grep noexec

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

COS节点上的大多数文件系统都带有“noexec”标志,因此无法从中执行二进制文件

一些变通办法:

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

如果您想一次性运行二进制,而不想处理另一个PD,您也可以安装一个tmpfs设备并从那里运行它

sudo mkdir /mnt/disks/scratch
sudo mount -t tmpfs tmpfs /mnt/disks/scratch/

一种解决方案是使用另一个图像系列,例如
ubuntu


在那里,
/tmp/
没有安装
noexec

,这真是太糟糕了。如何安装nvidia驱动程序和在启动脚本时运行的docker?当我尝试用gpu启动docker时,启动脚本对我不起作用。