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?

  • How do I make my Kubernetes replication controller use a certain secret to pull an image?
  • org.jolokia:docker-maven-plugin:0.10.4:push (code: 500, Internal Server Error)
  • How to manage inter-dependant docker containers when moving between or cloning environments
  • How to initialize and run Docker on windows?
  • Suggestion for alignment issue in desktop
  • Docker compose getting stuck
  • 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 --dns argument.

    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 my-dns-server-image, though.

  • How can I import a library from github to GO playground?
  • Is there docker orchestration for Hadoop cluster
  • Create a runit service that doesn't automatically start
  • docker not creating correct docker.sock groupon Ubuntu 16.04
  • Running Watchdog inside a container to monitor attached directories
  • Comunication between two docker-compose services?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.