3

I'm trying to use Elasticsearch with docker.

And you can see the guide here -> https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

my docker-compose.yml below

version: '2.2'
services:
  elasticsearch1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: elasticsearch1
    environment:
      - node.name=master-node
      - cluster.name=es-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es-data01:/usr/share/elasticsearch/data
    ports:
      - 127.0.0.1:9200:9200
      - 127.0.0.1:9300:9300
    networks:
      - elastic
    stdin_open: true
    tty: true

  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: elasticsearch2
    environment:
      - node.name=data-node1
      - cluster.name=es-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch1"
    ports:
      - 127.0.0.1:9301:9300
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es-data02:/usr/share/elasticsearch/data
    networks:
      - elastic
    stdin_open: true
    tty: true

volumes:
  es-data01:
    driver: local
  es-data02:
    driver: local

networks:
  elastic:
   # driver: bridge

the problem is

  1. I cannot connect by curl -XGET localhost:9200
  2. docker container exits automatically after few seconds

can you help me?

ps : when I try docker run it works. what is the difference between them?

docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch -it --rm -v els:/usr/share/elasticsearch/data -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.7.0

JS_Kim
  • 81
  • 1
  • 6
  • 1
    I found some clue. when `docker run` without `-e "discovery.type=single-node"` option container exits too... but don't know why – JS_Kim May 27 '20 at 08:12
  • did you get a chance to go through my answer and links provided in that, let me know if you need further information. – Amit May 28 '20 at 01:20

3 Answers3

2

Please check the container logs by using docker logs <your stopped container-id>, here you can get the container id using docker ps -a command.

Also please follow this SO answer and set the memory requirements which would help you run the Elasticsearch in docker. if it doesn't help then provide the logs which you can get as explained earlier.

Based on comments adding the updated docker-compose

version: '2.2'
services:
  elasticsearch1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: elasticsearch1
    environment:
      - node.name=master-node
      - node.master=true
      - cluster.name=es-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "cluster.initial_master_nodes=master-node"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es-data01:/usr/share/elasticsearch/data
    ports:
      - 127.0.0.1:9200:9200
      - 127.0.0.1:9300:9300
    networks:
      - elastic
    stdin_open: true
    tty: true

  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: elasticsearch2
    environment:
      - node.name=data-node1
      - node.master=false
      - cluster.name=es-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "cluster.initial_master_nodes=master-node"
    ports:
      - 127.0.0.1:9301:9300
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es-data02:/usr/share/elasticsearch/data
    networks:
      - elastic
    stdin_open: true
    tty: true

volumes:
  es-data01:
    driver: local
  es-data02:
    driver: local

networks:
  elastic:
   # driver: bridge
Amit
  • 30,756
  • 6
  • 57
  • 88
  • I found these error logs `max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]` and `the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured` – JS_Kim May 28 '20 at 07:43
  • great so you have two issues, first will be solved by https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html and another I am pinging soon. – Amit May 28 '20 at 07:56
  • Thanks for help, memory problem solved. Can you help second error? – JS_Kim May 28 '20 at 07:56
  • @JS_Kim, yeah doing that – Amit May 28 '20 at 07:57
  • OK, I'll try it. I guess.. the added line assigns master-node? so make link between two nodes? – JS_Kim May 28 '20 at 08:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214799/discussion-between-opster-elasticsearch-ninja-and-js-kim). – Amit May 28 '20 at 08:08
1

As you are following this article, https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

worth checking the second section with limits and memory resources as the containers in docker-compose is exiting due to low resources.

nischay goyal
  • 3,206
  • 12
  • 23
0

Exited with code 137 error is because of resource limitation (usually RAM) on the host machine. You can resolve this problem by adding this line to the environment variables of your docker-compose file:

- "ES_JAVA_OPTS=-Xms512m -Xmx512m"

You can read more about heap size settings, on official Elasticsearch documentation, in this link.

Mostafa Ghadimi
  • 5,883
  • 8
  • 64
  • 102