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.

Docker Containers using Elasticsearch and DNS Round Robin

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.

docker container run -d --name search1 --net-alias search --net my-net elasticsearch:2
docker container run -d --name search2 --net-alias search --net my-net elasticsearch:2

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.

docker container run -it --rm --name client --net my-net alpine nslookup search

Name:      search
Address 1:
Address 2:

Run cURL on CentOS Linux for Elasticsearch 2

Now let’s run cURL on CentOS so we can see both Elasticsearch servers responding to requests for search.

docker container run -it --rm --name client --net my-net centos:7 bash

# curl -s search:9200
    "name" : "Magma",

# curl -s search:9200
    "name" : "Melee",

This tutorial showed how to:

  • Create a custom Docker network.
  • Create Docker containers and connect them to a custom Docker network.
  • Specify a network alias for Docker containers.
  • Spin up an Alpine Linux Docker client and use NSLookup.
  • Run a CentOS Docker container and use cURL to search with Elasticsearch 2.

Awesome stuff!