Restart a Docker service when config changes

How would you restart a service, say for example ‘nginx‘ when a config file changes? For example I’ve got Puppet creating some nginx cfg files and place them on a volume which is mounted to my nginx container. At the moment I am using docker-gen, but are there any other methods?

  • Authenticating Jupyter Notebook inside Docker keeps resulting in invalid token
  • Docker-Compose - Server exposes several ports but only one of the ports is not accessible in the client
  • How does Spread know to update image in Kubernetes?
  • RavenDb - Status Code: NotFound
  • SIGTERM not received by java process using 'docker stop' and the official java image
  • Docker warning on cgroup swap limit, memory.use_hierarchy
  • Java application cannot get IP address of the host in docker container with static IP
  • Does Docker USER source .bashrc before running commands?
  • How to pass supervisor an environment variable from the docker run command
  • Error cannot find -lz building MariaDB on a debian based container
  • Docker's healthcheck on Windows container and exit code (“||” linux equivalent)
  • Connection nodejs and mongo with docker
  • One Solution collect form web for “Restart a Docker service when config changes”

    Docker containers are meant to be ephemeral. Also, Docker containers “containerize” whatever process you are running by making that process PID 1 inside your container. That means there is no traditional init system. In fact, no init system at all. And as you know, when the process inside your container exits, the container dies. So if we approach the problem from the standpoint of implementing ephemeral containers, you don’t restart your service. You create a new container using your modified configuration. And as mentioned in the comments by thaJeztah, you can docker restart nginx your container to refresh the configuration.

    Now, there are a couple of ways to hammer this square peg into a round hole. You are better than that… However, You’ve already noticed that docker-gen will get you nearly there. Likewise, if you take a dive into how the jwilder/nginx-proxy image works, you’ll get a better idea of how docker-gen works in practice. But you’ve probably already seen that, since you’re already using docker-gen.

    The other option is to shoehorn in something like supervisord. There is plenty of information about doing that online. Tons of people have done this in the past. And so for other people that may not understand why that solves the problem, supervisord becomes your container’s PID 1, and allows you to restart the child nginx processes “like normal”, but without killing your container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.