Home > Net >  ElasticSearch - cannot run two es docker containers at the same time
ElasticSearch - cannot run two es docker containers at the same time

Time:05-18

ElasticSearch - cannot run two es docker containers at the same time

I'm trying to run 2 services of ElasticSearch using docker-compose.yaml

Every time I run docker-compose up -d only one service is working at time. When I try to start stopped service it runs but the first one which was working before, stops immediately.

This is how my docker-compose.yaml looks like:

version: '3.1'
services:
  es-write:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    container_name: es-write
    environment:
      - discovery.type=single-node
      - TAKE_FILE_OWNERSHIP=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
  es-read:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    container_name: es-read
    environment:
      - discovery.type=single-node
      - TAKE_FILE_OWNERSHIP=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9201:9200
  sqs:
    image: "roribio16/alpine-sqs:latest"
    container_name: "sqs"
    ports:
      - "9324:9324"
      - "9325:9325"
    volumes:
      - "./.docker-configuration:/opt/custom"
    stdin_open: true
    tty: true

CodePudding user response:

Tldr;

I believe you get the known <container name> exited with code 137 error.

Which is docker way of telling you it is OOM (out of memory).

To solve

Define a maximum amount of Ram each container is allowed to use. I allowed 4GB, but you choose what suits you.

version: '3.1'
services:
  es-write:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    container_name: es-write
    environment:
      - discovery.type=single-node
    ports:
      - 9200:9200
    deploy:
      resources:
        limits:
          memory: 4GB  # Use at most 50 MB of RAM
  es-read:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
    container_name: es-read
    environment:
      - discovery.type=single-node
    ports:
      - 9201:9200
    deploy:
      resources:
        limits:
          memory: 4GB  # Use at most 50 MB of RAM
  • Related