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 "" --env "constraint:node==node1" my-dns-server-image
docker run -d -p "" --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?

  • elastic-beanstalk docker app not updating upon deploy
  • Docker containers linking
  • How do I install a specific version of Docker on Ubuntu?
  • grails/mysql with docker compose
  • Docker 1.12 on Mac issue with DB connection pool
  • How to config my nginx to a running container with rails using raspian?
  • 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.

  • Create a new image using REST API by placing the content in the request body
  • CoreOS: fleetctl status shows service inactive, while container is up
  • supervisor curl command failing with exit 56 error
  • Installing docker 17 version on centos 7
  • Windows docker container cannot ping host
  • Docker localhost IP
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.