google-cloud-platform - 无法在 Google Container-Optimized OS 上运行可执行的 shell 脚本

标签 google-cloud-platform google-container-os

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

$ chmod +x test.sh
$ ./test.sh Johnny
hello Johnny

但是在 Google Cloud Platform Container-Optimized OS 上,我得到 -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

最佳答案

COS 节点上的大多数文件系统都挂载了“noexec”标志,因此您无法从它们执行二进制文件。

一些解决方法:

  • 对于脚本,使用脚本作为参数调用解释器,"bash/path/script.sh", "python/path/app.py"
  • 在/mnt/disks 下挂载一个额外的数据磁盘。您可以在没有“noexec”标志的情况下安装它。使用启动脚本在启动时挂载。
  • 关于google-cloud-platform - 无法在 Google Container-Optimized OS 上运行可执行的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49037720/

    相关文章:

    go - Apache Beam 使用 Go 编写 PubSub 消息

    machine-learning - 当您的模型在 Google Cloud 上进行训练时,您可以关闭计算机吗?

    apache-spark - 在数据帧上使用partitionBy时出现dataproc警告

    docker - Google Cloud 上的 Jupyter Docker

    stackdriver - 如何在 Container-Optimized OS 中更改 logName 并配置 stackdriver 日志代理?

    docker - 如何启用Google Container Optimized OS交换限制支持

    java - Google Cloud 语音 API 中转录的文件大小

    python - 将文件从 URL 传输到 Cloud Storage

    docker - Google的Container OS可以与Compute Engine上的gRPC一起使用吗?

    docker - 在Google Cloud实例上独立安装kubelet永久磁盘