JS_Kim
JS_Kim

Reputation: 81

About docker container's exit when docker-compose up

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

Upvotes: 3

Views: 4914

Answers (3)

Mostafa Ghadimi
Mostafa Ghadimi

Reputation: 6776

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.

Upvotes: 1

Amit
Amit

Reputation: 32386

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

Upvotes: 2

nischay goyal
nischay goyal

Reputation: 3480

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.

Upvotes: 1

Related Questions