Creating Elasticsearch Docker Containers and Using DNS Round Robin

I’m enjoying a course on Docker, learning all about images, containers, and networking. One of the assignments teaches how Docker uses the container name for DNS in the network.

When creating a Docker container there is an option that allows one to assign the same network alias to 2 or more containers, allowing either container to respond to client requests. This provides a DNS Round Robin scenario where the containers take turns responding to client requests.

Create Custom Docker Network

There are a number of ways to approach the assigment, but I will first create a custom Docker network, called my-net.

docker network create my-net

Create 2 Docker Containers Running Elasticsearch 2

Now I will create 2 Docker containers running Elasticsearch 2 on the custom network. I’ve called the containers search1 and search2, respectively, and gave them the same network alias of search using the --net-alias option.

Run Nslookup Using Alpine Linux for DNS

Next I’ll add an Alpine Linux Docker container to the custom network to do an nslookup on search and we will see the two docker containers associated with search. This is the DNS Round Robin scenario that I mentioned earlier.