从另一个Docker容器在Docker容器中运行shell脚本?
问题描述:
如果在主机上,可以使用以下命令在Docker容器中启动脚本:
If I am on my host machine, I can kickoff a script inside a Docker container using:
docker exec my_container bash myscript.sh
但是,假设我要在另一个容器 bob
的 my_container
中运行 myscript.sh
.如果我在 bob
的外壳中时在上面运行了该命令,则该命令将不起作用(Docker甚至没有安装在 bob
中).
However, let's say I want to run myscript.sh
inside my_container
from another container bob
. If I run the command above while I'm in the shell of bob
, it doesn't work (Docker isn't even installed in bob
).
做到这一点的最佳方法是什么?
What's the best way to do this?
答
使用类似的东西简单地启动容器
Simply launch your container with something like
docker run -it -v/var/run/docker.sock:/var/run/docker.sock -v/usr/bin/docker:/usr/bin/docker
..
它应该可以解决问题