求证一下 dockerfile CMD 命令能否执行通过 volumes 映射的目录里的可执行文件?

docker-compose.yml 文件内容片段如下:

    volumes: #映射宿主机和容器目录,数据是永久保存的
      - ./ubuntu/shell/:/myShell/

dockerfile 文件的末尾内容如下:

CMD ["/mySheel/init.sh"]

现在的问题是通过 docker-compose.yml 配置文件启动容器的时候总是报错如下:

Removing us-01-php7.4
Recreating 87356591e344_us-01-php7.4 ... error

ERROR: for 87356591e344_us-01-php7.4  Cannot start service ubuntu-001: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/mySheel/init.sh": stat /mySheel/init.sh: no such file or directory: unknown

ERROR: for ubuntu-001  Cannot start service ubuntu-001: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/mySheel/init.sh": stat /mySheel/init.sh: no such file or directory: unknown
ERROR: Encountered errors while bringing up the project.

实际上 ./ubuntu/shell/init.sh 这个文件在宿主机上是存在的。

我现在不确定能否通过 CMD 命令启动映射目录里的文件?请高手解惑,谢谢。

阅读 1.8k
1 个回答

自己测试出来了,实锤了,突然就可以了!这个可执行文件必须要有可执行的权限。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题