Introduction

This post is about hosting ElasticSearch cluster on dockerised environment. We are also running Kibana configured on running ElasticSearch cluster.

Steps to create ElasticSearch cluster using Docker

Create docker compose file: docker-compose.yml

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.3.1
    container_name: es01
    environment:
      - node.name=es01
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.3.1
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet
  kibana:
    image: docker.elastic.co/kibana/kibana:7.3.1
    container_name: kibana
    environment:
      SERVER_NAME: kibana.local
      ELASTICSEARCH_HOSTS: http://es01:9200
    ports:
      - 5601:5601
    networks:
      - esnet

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:

Run docker-compose

docker-compose up -d

Access Kibana

<host>:5601

For first few seconds, you might see message: Kibana is not ready yet Try refreshing after some time. It will open up Kibana for you.

Special Notes

You might need to do following configuration, if your container died after few seconds (see the logs of your container):

In file: /etc/sysctl.conf

Append in end:
    vm.max_map_count=262144

Check health of ElasticSearch and Kibana

For ElasticSearch:

curl http://127.0.0.1:9200/_cat/health

Output will be look like:
1567757045 08:04:05 docker-cluster green 2 2 10 5 0 0 0 0 - 100.0%

For Kibana:

Either open in browser:
<hostname>:5601/status

Or, via api:
curl http://127.0.0.1:5601/api/status