如何在docker容器的主机上运行shell脚本? [英] How to run shell script on host from docker container?

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

问题描述

如何从docker容器控制主机?

How to control host from docker container?

例如,如何执行复制到主机的bash脚本?

For example, how to execute copied to host bash script?

推荐答案

这真的取决于你需要的bash脚本!

That REALLY depends on what you need that bash script to do!

例如,如果bash脚本只是回声一些输出,你可以做

For example, if the bash script just echoes some output, you could just do

docker run --rm -v $(pwd)/mybashscript.sh:/mybashscript.sh ubuntu bash /mybashscript.sh

另一种可能性是您希望bash脚本安装一些软件 - 说脚本来安装docker-compose。你可以做一些类似

Another possibility is that you want the bash script to install some software- say the script to install docker-compose. you could do something like

docker run --rm -v /usr/bin:/usr/bin --privileged -v $(pwd)/mybashscript.sh:/mybashscript.sh ubuntu bash /mybashscript.sh

但是这一点,您真的需要知道脚本正在做什么,以便在容器内允许主机上需要的特定权限。

But at this point you're really getting into having to know intimately what the script is doing to allow the specific permissions it needs on your host from inside the container.

这篇关于如何在docker容器的主机上运行shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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