Docker Community Forums

Share and learn in the Docker community.

Updating /etc/hosts without container restart


(Yashgt) #1


In a compose file I have a section that provides extra_hosts. These entries go into the /etc/hosts file of the containers started by the compose up. If the IP address of any of the external hosts changes, I would like to get the /etc/hosts files of all containers updated. Currently I have to update the extra_hosts section and then restart the containers using docker-compose down and up.

Is it possible to get the compose file changes reflected in the container’s /etc/hosts file without restarting the containers?


(Joffrey F) #2

Hi Yash,

It isn’t possible, and even if it was, it probably wouldn’t be a good idea - if that container restarts after a failure for some reason, any changes to your /etc/hosts would be lost as well.

Note that you don’t have to bring your whole stack down when you make changes ; when you run docker-compose up, Compose will automatically detect what changed in your configuration and only recreate the containers that need it. If your main concern is downtime, this would reduce it significantly, provided your architecture is reasonably failure resilient.