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?

  • Deleting images from a private docker registry
  • Docker - Run Apache on host and container for different websites
  • Using Docker with nodejs with node-gyp dependencies
  • How to create a Docker image of centos provisioned with apache?
  • Which file stores the docker image dependencies?
  • Docker show current registry
  • Running a longer command from docker
  • Cron and Crontab files not executed in Docker
  • X509 parsing error, 'negative serial number' while pulling repository
  • Failed to connect to port 443: Connection refused, Failed to Bootstrap, Discourse Docker
  • Docker Apache Proxy point to running Python Script
  • Docker commit alterations of a built image
  • 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.