如何从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.