How to provide dynamic hostnames for all docker containers?

I currently have one machine that I am running docker images on. I want all containers to be accessible via hostname based on container name. So, if I have a container C1

and C2

, and the host for the docker server is mydocker.local

, then it c1.mydocker.local

will point to the container image C1

, and if I were to run C3

it would become available as C3.mydocker.local

.

docker-dns looks like what I'm trying to do, but the project hasn't been updated in 7 months and the documentation wasn't enough for me to make it work.

This seems like a very common use case, but I haven't been able to create a suitable google query magic to find anything.

+3


source to share


2 answers


You can try docker-gen to automatically update your host file, hosts

or create a service dns

like Dnsmasq

,



Also I found a docker image called dns-gen which just uses docker-gen and dnsmasq might solve your problem.

+1


source


You should use explicit binding if containers will depend on each other. This will update the hosts' hosts file inside the container to add the IP addresses for each of the associated containers.



If you want something like Rancher , you get a complete VPN where each of the containers has its own IP address, Rancher also supports services that will support DNS for all running containers. The bonus for using a rancher is that it will work in a multi-host scenario as well.

0


source







All Articles