gpt4 book ai didi

docker - 从共享卷在Docker上运行Shell脚本

转载 作者:行者123 更新时间:2023-12-02 18:24:24 24 4
gpt4 key购买 nike

我有一个与主机共享卷的Docker容器。该卷将安装在根主文件夹中。在该文件夹中,我有一个要在容器启动并运行后运行的shell脚本。

我正在使用以下命令:

docker exec -i localserver_web_1 sh /root/scripts/define_applications.sh

但我得到这个回应:
sh: 0: Can't open /root/scripts/define_applications.sh

当我从容器内部运行脚本时,脚本运行良好。它说它在/ root / scripts /中。我的权限设置为777。我怎么可能做错了?

最佳答案

可以肯定的是,请在命令 shell 中尝试使用tty以root用户身份执行并执行:

docker exec -it -u root localserver_web_1 sh -c '/root/scripts/define_applications.sh'

如果不起作用,请至少通过 docker exec 检查其存在和内容:
docker exec -it -u root localserver_web_1 sh -c 'ls -alrt /root/scripts'
docker exec -it -u root localserver_web_1 sh -c 'cat /root/scripts/define_applications.sh'

还检查图像以检查其 ENTRYPOINT(类似 to the check for its CMD ):
docker inspect --format='{{.Config.Entrypoint}}' <image:tag>

OP Jon Schwartz确认 in the comments:

this was a pebkac error.
The script is actually called define-applications.sh, not define_applications.sh.
The cat line showed me my issue. When it could see the script through ls, I knew it should be able to get to it. When it couldn't cat out, I realized what happened.

关于docker - 从共享卷在Docker上运行Shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34188041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com