version: '3.4'

services:
    es01:
        image: &image docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION:-7.15.2}
        command: &command >
            /bin/sh -c "./bin/elasticsearch-plugin list | grep -q ingest-attachment
            || ./bin/elasticsearch-plugin install --batch ingest-attachment;
            chown elasticsearch /usr/share/elasticsearch/repository;
            /usr/local/bin/docker-entrypoint.sh"
        environment: &environment
            node.name: es01
            cluster.name: es-docker-cluster
            cluster.initial_master_nodes: es01
            discovery.seed_hosts: es01
            bootstrap.memory_lock: 'true'
            ES_JAVA_OPTS: -Xms512m -Xmx512m
            path.repo: /usr/share/elasticsearch/repository
        ulimits: &ulimits
            memlock:
                soft: -1
                hard: -1
        volumes:
            - data01:/usr/share/elasticsearch/data
            - esrepo:/usr/share/elasticsearch/repository
        ports:
            - 9200:9200
        networks: &networks
            - elastic
    es02:
        image: *image
        command: *command
        environment:
            <<: *environment
            node.name: es02
        ulimits: *ulimits
        volumes:
            - data02:/usr/share/elasticsearch/data
            - esrepo:/usr/share/elasticsearch/repository
        networks: *networks
volumes:
    data01:
    data02:
    esrepo:

networks:
    elastic:
        driver: bridge
