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
  • 23,662
  • 12
  • 81
  • 137
DarVar
  • 15,372
  • 25
  • 90
  • 130

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
  • 19,380
  • 4
  • 31
  • 51
0

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

dukebody
  • 6,675
  • 3
  • 35
  • 56
  • 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,402
  • 6
  • 40
  • 54