Prerequisites


This article assumes that the Docker-CE is installed and the daemon is running.
Additionally, the kernel variable vm.max_map_count must be set to at least 262144, using the command:

sysctl -w vm.max_map_count=262144
Bash
 to

To make this change permanent, a line can be added to /etc/sysctl.conf file:

grep vm.max_map_count /etc/sysctl.conf
vim /etc/sysctl.conf
vm.max_map_count=262144


Deploying an ElasticSearch Cluster with Docker
In this article the objective is to provision a three node ElasticSearch cluster, making use of the docker batch-processing tool "docker-compose".


We'll be using the official docker image for ElasticSearch: docker.elastic.co/elasticsearch/elasticsearch:7.11.1


Firstly, create a file docker-compose.yml using the following code:



version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic

es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic

es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic


volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local

networks:
elastic:
driver: bridge

This file has all the configurations to create three elasticsearch containers, a communication network and data volumes for them.


You can bring up the cluster using:

docker-compose up -d 
Bash
 to

To monitor the bring up, use the following command:

watch docker ps 
Bash
 to

Once the cluster is up and stable, use CTRL + C to quit the watch. 

We can now verify the cluster by hitting the cat nodes endpoints:

curl -X GET "localhost:9200/_cat/nodes?v&pretty"
Bash
 to

The output of the above would look similar to:

Output

ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.24.0.2 64 19 0 0.01 0.02 0.00 cdhilmrstw - es02 172.24.0.3 65 19 0 0.01 0.02 0.00 cdhilmrstw - es01 172.24.0.4 59 19 0 0.01 0.02 0.00 cdhilmrstw * es03