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

查看:109
本文介绍了如何从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天全站免登陆