How to tell a docker container that is deployed to a random machine in a cluster to use DNS on its own host?
Consider the following configuration:
// Create a swarm cluster docker-machine create -d virtualbox --swarm --swarm-master node1 docker-machine create -d virtualbox --swarm node2 // Setup shell environment to talk to the swarm cluster eval $(docker-machine env --swarm node1) // Run a DNS server on each swarm machine docker run -d -p "172.17.0.1:53:53" --env "constraint:node==node1" my-dns-server-image docker run -d -p "172.17.0.1:53:53" --env "constraint:node==node2" my-dns-server-image // Run a custom service, deployed to a random node in the swarm docker run -d my-custom-service
How do I tell my custom service to use the DNS server that is running on its own host?
I know about the
--dns argument that can be passed to
docker run, but the problem is that I don’t know which host the container will be deployed to, and thus I don’t know either (A) the host IP or (B) the gateway IP for the bridge network on that host at the time that
docker run is called, thus it doesn’t seem like I can take advantage of the
I’m aware that I could modify the
my-custom-service image to execute some shell commands to get its gateway and add a line to /etc/resolv.conf at runtime, but I’m trying to do this without having to modify the
my-custom-service image. It is completely acceptable for me to modify the