4

Is there anyway I can get Docker to update the /etc/hosts of all containers?

I want each container running on the host machine to know the hostname of all other containers running on the host machine.

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
DarVar
  • 16,882
  • 29
  • 97
  • 146

3 Answers3

1

You could use next approach: use own dns server (dnsmasq is easy choice) and update it with addresses of all running containers dynamically (either via polling or using docker events). Here couple of samples: 1, 2, 3.

ISanych
  • 21,590
  • 4
  • 32
  • 52
0

Yes, you can. It is automatically done when you link the containers: https://docs.docker.com/userguide/dockerlinks/#updating-the-etchosts-file

dukebody
  • 7,025
  • 3
  • 36
  • 61
  • 1
    I tried this but only the parent container knows the child containers hostname. The child container doesn't know the parents hostname. The link is one way it seems. – DarVar Dec 05 '14 at 11:18
  • hmmmm see http://stackoverflow.com/questions/25324860/how-to-create-a-bidirectional-link-between-containers – dukebody Dec 05 '14 at 11:23
  • 1
    see also http://stackoverflow.com/questions/27048319/docker-linking-how-can-both-containers-know-each-others-ip/27067586#27067586 – Bryan Dec 05 '14 at 12:11
0

You can try using weave, which is a project I am working on. It gives you an overlay network with DNS, so you can forget about the hosts files, linked containers and most of those things.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54