pgreen2
pgreen2

Reputation: 3651

How do I provide dynamic host names for all docker containers?

Currently, I have a single machine I'm starting to run docker images on. What I want to do is have all containers accessible through a host name based upon the container name. So, if I have container C1 and C2, and the host for the docker server is mydocker.local, then c1.mydocker.local will point to container image C1 and if I were to run C3, it would become available as C3.mydocker.local.

docker-dns seems similar to what I'm trying to do, but the project hasn't been updated for 7 months and documentation was not enough for me to get it running.

This seems like a very common use case, but I have not been able to create the appropriate google query magic to find anything.

Upvotes: 3

Views: 1607

Answers (2)

Usman Ismail
Usman Ismail

Reputation: 18679

A you should use explicit linking if containers are going to depend on each other. This will update the etc hosts file inside the container to add IPs for each of the linked containers.

If you do want something something like Rancher will give you a complete virtual private network in which each of the containers has its own IP. Rancher also supports services which will maintain DNS for all running containers. Bonus for using rancher is that it will work in a multi-host scenario as well.

Upvotes: 0

Freeznet
Freeznet

Reputation: 537

You can try docker-gen to automatic update your host's hosts file, or create a dns service such as Dnsmasq.

Also I found an docker image called dns-gen which just using docker-gen and dnsmasq, might solve your problem.

Upvotes: 1

Related Questions