在docker上从共享卷运行shell脚本 [英] Run shell script on docker from shared volume

查看:152
本文介绍了在docker上从共享卷运行shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker容器与主机共享卷。卷安装在根主文件夹中。在该文件夹中,我有一个shell脚本,我想在容器运行后运行。



我使用这个命令:

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

但我得到这个回应:

  sh:0:无法打开/ root / scripts / define_applications.sh 

当我从容器内部运行脚本时,脚本工作正常。它说它在/ root / scripts /。我有权限设置在777.我可以做错什么?

解决方案

只要确定,尝试以root身份执行,在命令shell中使用tty:

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

如果不起作用,请至少通过 docker exec : p>

  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 (类似于查看其 CMD ):

  docker inspect --format ='{{。Config .ENT rypoint}}'< image:tag> 

OP Jon Schwartz 确认在评论


这是一个pebkac错误。

该脚本实际上被称为 define-applications.sh ,而不是 define_applications.sh

cat line向我显示我的问题。当它可以通过ls看到脚本,我知道应该能够得到它。当它不能 cat 出来,我意识到发生了什么。



I have a docker container that has a shared volume with the host. The volume mounts in the root home folder. In that folder, I have a shell script I want to run once the container is up and running.

I was using this command:

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

but I'm getting this response:

sh: 0: Can't open /root/scripts/define_applications.sh

The script is working fine when I run it from inside the container. It says it's in /root/scripts/. I have permissions set at 777. What could I be doing wrong?

解决方案

Just to be sure, try and exec as root, with a tty, in a command shell:

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

If it does not work, check at least its presence and content through 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'

Also inspect the image to check its ENTRYPOINT (similar to the check for its CMD):

docker inspect --format='{{.Config.Entrypoint}}' <image:tag>

The OP Jon Schwartz confirms 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上从共享卷运行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆