title: Docker, running multiple container (elasticsearch)
body: <p>I'm running one elasticsearch with</p>
  
  <pre><code>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
  </code></pre>
  
  <p>(I think this one uses host's <code>/var/lib/elasticsearch</code> when container access <code>/usr/share/elasticsearch/data</code> and the data is persisted in the <code>/var/lib/elasticsearch</code> of the host)</p>
  
  <p>Another one with </p>
  
  <pre><code>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:
  </code></pre>
  
  <p>(I'm not sure how this one works out, but I guess docker provides persistant storage that can be accessed via <code>/usr/share/elasticsearch/data</code> from container)</p>
  
  <p>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.</p>
  
  <p>I have a kibana running which looks at the first ES.  </p>
  
  <p>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.   </p>
  
  <p>What am I misunderstanding? </p>
  
  <p>.env</p>
  
  <pre><code>ELASTICSEARCH_PORT_DEV=29200
  ELASTICSEARCH_PORT_SEARCH_DEV=29300
  </code></pre>