简体   繁体   English

在Docker容器外运行脚本

[英]Running script outside of docker container

I'm trying to do an automatic deploy, so... 我正在尝试自动部署,所以...

I have a .sh script to automatically pull docker images, for example: 我有一个.sh脚本来自动提取docker图像,例如:

docker pull mongo
docker stop db
docker rm db
docker run --name db -d mongo

And I am waiting for a POST request to start it. 我正在等待POST请求来启动它。

So I have a container (with nginx) to act as a server. 所以我有一个容器(带有Nginx)充当服务器。 But I have to call that script outside the container, because it can update any container. 但是我必须在容器外部调用该脚本,因为它可以更新任何容器。

Is that possible? 那可能吗? If so, how? 如果是这样,怎么办?

It sounds to me like you are looking for the Docker UNIX socket. 在我看来,您正在寻找Docker UNIX套接字。 See some explanation here (might be best to scroll down to the 'The Solution' part of that page. Basically, you would start your Nginx container with the mounted UNIX socket. This allows you to use the docker command from inside the Nginx container, on other sibling containers. 在此处查看一些说明(最好向下滚动至该页面的“解决方案”部分。基本上,您将使用已安装的UNIX套接字启动Nginx容器。这使您可以从Nginx容器内部使用docker命令,在其他同级容器上。

Important security note: 重要安全说明:

Using the UNIX socket is a definite security issue, especially if you are exposing it to the worldwide web. 使用UNIX套接字是一个明确的安全问题,尤其是当您将其暴露在全球范围内时。 See [1] and [2] . 参见[1][2] Other alternatives might include using Docker-in-Docker , though I am not certain that's suitable for your case right here. 其他替代方法可能包括使用Docker-in-Docker ,尽管我不确定此处是否适合您的情况。 Docker did publish a blogpost on how to secure the UNIX socket here , if that is the path you want to go. Docker确实在这里发布了有关如何保护UNIX套接字的博客文章,如果那是您要走的路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM