【问题标题】:File not being bind mounted to docker-compose文件未绑定安装到 docker-compose
【发布时间】:2020-09-07 05:07:34
【问题描述】:

我正在运行docker-compose 测试;我的堆栈中将执行实际测试的一部分是以下服务

  tester:
    image: tutum/curl:latest
    volumes:
      - ./ci/wait-for-it.sh:/usr/local/bin/wait-for-it.sh
      - ./webhooks:/app/webhooks
    depends_on:
      - sut
    command: ["wait-for-it.sh", "sut:8080", "-t", "240", "--", "sh", "pytest /app/webhooks"]

命令失败如下:

ERROR: for 0114c9206690_alerta-_tester_1  Cannot start service tester: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"wait-for-it.sh\": executable file not found in $PATH": unknown

ERROR: for tester  Cannot start service tester: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"wait-for-it.sh\": executable file not found in $PATH": unknown

被挂载的文件确实存在:

▶ ls docker-compose.test.yaml
docker-compose.test.yaml

Workspace/systems-utils/  alerta_dev_infra ✗                                                                         1d ⚑ ◒
▶ ls ./ci/wait-for-it.sh
./ci/wait-for-it.sh

更重要的是,当尝试绑定挂载一个不存在的文件时,我得到的不是与挂载相关的错误,而是与上述相同的错误

  tester:
    image: tutum/curl:latest
    volumes:
      - ./ci/foofile.sh:/usr/local/bin/wait-for-it.sh
      - ./webhooks:/app/webhooks
    depends_on:
      - sut
    command: ["wait-for-it.sh", "sut:8080", "-t", "240", "--", "sh", "pytest /app/webhooks"]
$ docker-compose -f docker-compose.test.yaml up -d

ERROR: for tester  Cannot start service tester: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"wait-for-it.sh\": executable file not found in $PATH": unknown
ERROR: Encountered errors while bringing up the project.

我错过了什么?

编辑:关于提到的PATH问题,这里是:

▶ docker run -it tutum/curl:latest printenv
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=1f3090676fa0
TERM=xterm
HOME=/

更重要的是,tester 服务配置与this 项目中的完全相同,运行完美。

关于权限问题:

Workspace/systems-utils/alerta-workable  alerta_dev_infra ✗                                                                        1d ⚑ ◒  ⍉
▶ ls -al ./ci/wait-for-it.sh
-rwxr-xr-x  1 pkaramol  staff   5.1K Sep  6 22:02 ./ci/wait-for-it.sh

【问题讨论】:

    标签: docker docker-compose


    【解决方案1】:

    错误消息非常不言自明 - wait-for-it.sh 不在 $PATH 上。

    您需要将 /usr/local/bin 添加到 $PATH 或将命令更改为

    command: ["/usr/local/bin/wait-for-it.sh", "sut:8080", "-t", "240", "--", "sh", "pytest /app/webhooks"]
    

    另请参阅对此question 的已接受答案,了解为什么/usr/local/bin 可能不在路径中。

    【讨论】:

      【解决方案2】:

      似乎在 $PATH 中找不到“executable 文件”

      那么让我们尝试在./ci/wait-for-it.sh文件上设置可执行权限:

      $ chmod +x ./ci/wait-for-it.sh
      

      【讨论】:

      • 我更改了文件的权限,但仍然出现同样的错误
      • @pkaramol 你能更新 docker-compose 文件以显示它是哪个版本吗?
      猜你喜欢
      • 2015-08-18
      • 2022-11-21
      • 2020-12-21
      • 2018-01-14
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多