从另一个Docker容器在Docker容器中运行shell脚本? [英] Run shell script inside Docker container from another Docker container?

查看:117
本文介绍了从另一个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 ..

它应该可以解决问题

这篇关于从另一个Docker容器在Docker容器中运行shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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