DNS round robin with Docker

Vinci Sharma
3 min readSep 5, 2020

--

Photo by Victoire Joncheray on Unsplash

We all know that Docker is the World’s leading container platform and an efficient way in which to package and deploy your apps especially to the Cloud. The powers are enhanced even further when coupled with orchestration technologies like Docker Swarm and Kubernetes.

The beauty of Docker lies in the ease and lightning speed with which containers can be stood up to perform a task and destroyed never to be seen again. In this story we look at setting up a simple DNS Round Robin solely using Docker, without any of the fancy orchestration tools.

Step 1 Create a new Docker network

Create a new Docker network

docker network create test
Creating the network

Check whether the new network has been created successfully

docker network ls
Verifying network creation

Step 2 Stand-up two containers on the newly created network

The two containers can be stood up by typing the below command twice

docker container run --detach --network test --network-alias search-test elasticsearch:2
Standing up the two containers

Check if the containers are up.

docker container ls
Checking container status

Step 3 Test the DNS Round Robin

For testing the DNS round robin, we need any container which will have the utilities nslookup , curl and will allow us to ping. A quick Google leads to this GitHub repo.

Stand up the test container by typing the below command. The test container is stood up on the same network and we get container shell access from the host.

docker container run -it --network test arunvelsriram/utils /bin/bash
Standing up the test container on the same network

Once the container shell is available type in

nslookup search-test

this returns back two IP addresses corresponding to each container behind search-test

Performing nslookup

To test the DNS round robin, two consecutive curls are performed

curl search-test:9200

and the response alternates between the two containers.

Sidewinder and Skein are two random names for easticsearch containers

pinging search-test twice, alternates between the two IP addresses.

ping search-test -c 1
Pinging to check DNS round robin

The three containers and the network can now be destroyed or you can keep them around to test DNS round robin with more than two containers.

--

--

No responses yet