Docker Community Forums

Share and learn in the Docker community.

Enabling DNS Round Robin


(Everett Toews) #1

I’d like to make use of the new feature in 1.11.0

Multiple A/AAAA records from embedded DNS Server for DNS Round robin (#21019)

I’ve got a minimal example with instructions but the DNS isn’t doing round robin.

My understanding is that DNS round robin can be enabled with a network alias like

          # All app servers be referred to by this alias with the backend network
          - apps

As you can see in this docker-compose.yml file.

Any app using the apps alias should be in a DNS round robin. So if I setup an nginx.conf file to use the apps alias I should see requests served by all app hosts.

However, in my example you can see the curl request always gets served by the same host.

Is there anything else I need to do to enable DNS round robin?

This happens on both Docker Toolbox 1.11.0 and Docker for Mac 1.11.0-beta7 (build: 5830)

(Jeff Anderson) #2

I just tried following that same example:

git clone ''
cd docker-dns-round-robin
docker-compose up -d
docker run --rm -it --net=dockerdnsroundrobin_backend azukiapp/dig dig apps.
docker-compose scale app=3
docker run --rm -it --net=dockerdnsroundrobin_backend azukiapp/dig dig apps.

(the azukiapp/dig image is one I found randomly on hub)

Before the scale, dig returned one address:

apps.			600	IN	A

After the scale, it returned all three containers:

apps.			600	IN	A
apps.			600	IN	A
apps.			600	IN	A

Since in my testing, I hit the nginx before I called scale, I ran into the same behavior that you did until I restarted the lb service with docker-compose restart lb. Then I was seeing responses from each container. Nginx will cache a DNS response for as long as the TTL. In this case, that is 600 seconds.

nginx can be configured to override this with a different value:

(Everett Toews) #3


And if you use the valid param on resolver you override that caching period. I also got some friendly help over here. I updated my example and it’s working now. Cheers.