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?

  • Access docker containers from local network via dev suffix
  • Fluentd capture stack traces from Docker
  • Docker and uPnP
  • /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
  • Docker Packages: Hash Sum Mismatch
  • Cannot return to shell session after script
  • 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.

  • Docker + Virtual Box = VT-x is not available (VERR_VMX_NO_VMX)
  • Minor change in ansible playbook does not get updated in target host
  • Connecting to a running Erlang application release in a docker container
  • Two Users in Docker
  • What's the point of data-only docker containers?
  • Azure VM with Docker failing to connect
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.