0

I'm running one elasticsearch with

version: '3'

services:
 elasticsearch:
  build:
    context: .
    dockerfile: ./compose/elasticsearch/Dockerfile
    args:
      - VERSION=${VERSION}
      - MEM=${MEM}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_DEV}
      - CLUSTER_NAME=${CLUSTER_NAME_DEV}
      - ENV=${ENV_DEV}
  container_name: elasticsearch
  network_mode: host
  environment:
    - discovery.type=single-node
  volumes:
   - /var/lib/elasticsearch:/usr/share/elasticsearch/data
 logstash:
  build:
    context: .
    dockerfile: ./compose/logstash/Dockerfile
    args:
      - VERSION=${VERSION}
      - ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST_DEV}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_DEV}
      - DB_HOST=${DB_HOST_DEV}
      - DB_NAME=${DB_NAME_DEV}
      - ENV=${ENV_DEV}
  container_name: logstash
  network_mode: host
  volumes:
   - /opt/logstash/data:/usr/share/logstash/data
  dns:
   -  192.168.1.1  # IP necessary to connect to a database instance external to where the server in which the container is running
 kibana:
  build:
    context: .
    dockerfile: ./compose/kibana/Dockerfile
    args:
      - VERSION=${VERSION}
      - ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST_DEV}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_DEV}
  container_name: kibana
  depends_on:
   - elasticsearch
  network_mode: host
 nginx:
  build:
    context: .
    dockerfile: ./compose/nginx/Dockerfile
    args:
      - KIBANA_HOST=${KIBANA_HOST_DEV}
      - KIBANA_PORT=${KIBANA_PORT_DEV}
  container_name: nginx
  network_mode: host
  depends_on:
   - kibana
 apm:
  build:
    context: .
    dockerfile: ./compose/apm/Dockerfile
    args:
      - VERSION=${VERSION}
      - ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST_DEV}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_DEV}
      - APM_PORT=${APM_PORT_DEV}
  container_name: apm
  depends_on:
   - elasticsearch
  network_mode: host

(I think this one uses host's /var/lib/elasticsearch when container access /usr/share/elasticsearch/data and the data is persisted in the /var/lib/elasticsearch of the host)

Another one with

version: '3'

services:
 elasticsearch-search:
  restart: always
  build:
    context: .
    dockerfile: ./compose/elasticsearch/Dockerfile
    args:
      - VERSION=${VERSION}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_SEARCH_DEV}
      - MEM=${MEM_SEARCH}
      - CLUSTER_NAME=${CLUSTER_NAME_SEARCH_DEV}
      - ENV=${ENV_DEV}
  container_name: elasticsearch-search
  network_mode: host
  environment:
    - discovery.type=single-node
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - data:/usr/share/elasticsearch/data

  ulimits:
    memlock:
      soft: -1
      hard: -1
    nofile:
      soft: 65536
      hard: 65536
 kibana:
  build:
    context: .
    dockerfile: ./compose/kibana/Dockerfile
    args:
      - VERSION=${VERSION}
      - ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST_SEARCH_DEV}
      - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT_SEARCH_DEV}
  container_name: kibana-search
  depends_on:
   - elasticsearch-search
  network_mode: host
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - data:/usr/share/elasticsearch/data

volumes:
  data:

(I'm not sure how this one works out, but I guess docker provides persistant storage that can be accessed via /usr/share/elasticsearch/data from container)

When I run them at the same time, I expect the two elasticsearch uses separate data. but it seems they are interfering with each other.

I have a kibana running which looks at the first ES.

When I run the first ES alone, I can see the data , but as soon as I run the second ES, there's nothing, no index-pattern, no dashboard.

What am I misunderstanding?

.env

ELASTICSEARCH_PORT_DEV=29200
ELASTICSEARCH_PORT_SEARCH_DEV=29300
5
  • can you provide the entire content of your compose file in both the case, also how you know they are interfering? Commented Dec 27, 2019 at 12:27
  • @OpsterESNinja-Amit I added the compose file, and why I think they are interfering Commented Dec 27, 2019 at 13:46
  • In the second file there should be a top-level volumes: section with a data: block within it; that is important to the question. Commented Dec 27, 2019 at 14:02
  • @DavidMaze oh yes, I have it on my compose file, missed that part when copying it. Commented Dec 27, 2019 at 14:13
  • In the second example where you're storing data in a named volume, how do you expect the data to get in there? (It seems like you're seeing what you expect, that the two ES installations have data stores isolated from each other.) Commented Dec 27, 2019 at 14:14

1 Answer 1

1

most probably something is wrong with your docker-compose in term of volumes: sections.

second example has this at the top

volumes:
   - data:/usr/share/elasticsearch/data

and this at the bottom:

volumes:
    - /etc/localtime:/etc/localtime:ro
    - data:/usr/share/elasticsearch/data

which means that at least two separate container have binding to the same local folder data. which is definitely way to see strange things, because something inside of those containers (ES is one of those) will try to recreate data storage hierarchy in hosts data folder.

can you just try defining volumes for first ES as:

volumes:
   - ./data/es1:/usr/share/elasticsearch/data

and for second one as:

volumes:
   - ./data/es2:/usr/share/elasticsearch/data

just make sure that ./data/es1 and ./data/es2 folders are there on your host before doing docker-compose up.

or you can post whole docker-compose.yml file so we can say what is wrong with it...

Sign up to request clarification or add additional context in comments.

6 Comments

i fixed the op.. the volumes: at the top was mean to be a snippet summary of docker-compose which follows.
in this case elasticsearch service and elasticsearch-search doesn't have conflict on drive. and they should be working at the same time just fine. (assuming your project is not located inside of /var/lib/elasticsearch, that is why i would recommend full path for second as well instead of data) ALSO i don't see you are exposing ports ``` ports: - 27017:27017 ``` which should be different port of host fo second ES. otherwise it will fail to start...
sorry, ES ports are ports: - 9200:9200
I copied the full docker-compose.. sorry should have done it sooner.
now i see, volumes on top level are designed to be common place among multiple services. So you have two options 1) - define two volumes as dataes1 and dataes2 and change your services to use them. or 2) - mount 2 host separate path instead of defined loume data here is a doc docs.docker.com/compose/compose-file/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.