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?

  • Using Laradock, the “display_errors” flag is not working
  • Kubernetes: Managing environment config
  • etcd username password with docker daemon parameters
  • Why orientDB connection to localhost of docker is refused
  • Not able to access Flask Web application running inside a Docker container
  • Unable to run build for gitlab-ci using docker on windows server
  • How to execute the Entrypoint of a Docker images at each “exec” command?
  • How to configure dns entries for Docker Compose
  • Get List of Official Docker Images
  • How to scale out VMs in Azure Container Service Docker?
  • Logging from one Docker Container to Another
  • Docker Registry vs Docker “Trusted” Registry
  • 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.