Docker Swarm and Elasticsearch

Hi,

Is there an example I can follow to setup Elasticsearch running on Docker Swarm? I am able to run Elasticsearch with Docker-Compose (single node). However, I am having a hard time to make Elasticsearch working on Docker Swarm (multiple nodes).

Any help will be much appreciated.

Hi @zee.caniago

If you are not looking for a way to secure the inter-node-communication, this configuration works for me:

docker-compose-elasticsearch.yml:

version: '3'
services:
  es01:
    container_name: es01
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
    environment:
      - node.name=es01
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,es02
      - bootstrap.memory_lock=false
      - "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    deploy:
      mode: replicated
      replicas: 2

  es02:
    container_name: es02
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
    environment:
      - node.name=es02
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,es02
      - bootstrap.memory_lock=false
      - "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    deploy:
      mode: replicated
      replicas: 2

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

Depending on the amount of swarm members you have, you may change the number of replicas or use the "global" mode (one container on each host).

Then you start the application with the following command:

docker stack deploy --compose-file docker-compose-elasticsearch.yml elasticsearch

Hope this helps

MiTschMR

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.