Search code examples
dockerautodeploy

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:

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.

So I have a container (with nginx) to act as a server. But I have to call that script outside the container, because it can update any container.

Is that possible? If so, how?


Solution

  • It sounds to me like you are looking for the Docker UNIX socket. 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.

    Important security note:

    Using the UNIX socket is a definite security issue, especially if you are exposing it to the worldwide web. See [1] and [2]. Other alternatives might include using Docker-in-Docker, though I am not certain that's suitable for your case right here. Docker did publish a blogpost on how to secure the UNIX socket here, if that is the path you want to go.