Install Elastic Search in a docker environment
 


You can install Elastic Search in a docker environment. For this to work, you need to make sure that you have the docker installed in your environment (linux/windows/mac etc). Once the docker is installed, you also need to check whether docker-compose is installed. For Windows environment, docker-compose is usually bundled with your docker installation. But for linux, you need to explicitly install docker-compose. You can install docker-compose using the command. Use pip to install.
pip install docker-compose

After you have installed docker-compose, create a file named docker-compose.yml with the below code:

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.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.0.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

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

networks:
  esnet:

The above yml defines two elastic search nodes running in port 9200 in a single cluster. Now you can install elastic search in your docker environment, using the below command.

docker-compose up

You can check whether the elastic search nodes are properly installed and running by connecting to your port 9200. You can do so using curl command.

curl http://127.0.0.1:9200/_cat/health
1472225929 15:38:49 docker-cluster green 2 2 4 2 0 0 0 0 - 100.0%

You can shut down the dockers running elastic search nodes by issuing the command:

docker-compose down

If you are getting this error: ERROR: for +es01 Cannot start service es01: driver failed programming external connectivity on endpoint es01
it means another instance of elastic search is already using the port 9200. So find that instance using "ps aux| grep elastic" and kill it. After that run docker-compose up again to start the nodes.

 
 
 
 
 
COPYRIGHT © 2017 java-samples.com. ALL RIGHTS RESERVED.