Elasticsearch not reachable from webapp and kibana containers

I have a docker-compose.yml file which declares webapp, postgres database, a two node elasticsearch, and a kibana container.

version: '3'
services:
  webapp:
    build:
      context: ../../../
      dockerfile: config/docker/dev/Dockerfile-dev
    container_name: MyWebApp-dev
    image: 'localhost:443/123'
    ports:
      - "4000:4000"
      - "3000:3000"
    depends_on:
      - db
      - elasticsearch
      - kibana
    links:
      - db
      - elasticsearch
      - kibana
  db:
    image: postgres:10
    container_name: db
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=mine_dev
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - esnet
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    environment:
      - node.name=es02
      - discovery.seed_hosts=elasticsearch
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet

  kibana:
    image: docker.elastic.co/kibana/kibana:7.0.1
    ports:
      - "5601:5601"
    container_name: kibana

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:

They all build successfully, but kibana cannot get a live connection to elasticsearch

kibana           | {"type":"log","@timestamp":"2019-05-08T23:36:13Z","tags":["status","plugin:searchprofiler@7.0.1","error"],"pid":1,"state":"red","message":"Status changed from red to red - No Living connections","prevState":"red","prevMsg":"Unable to connect to Elasticsearch."}

kibana           | {"type":"log","@timestamp":"2019-05-09T00:02:46Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}

and the index "products" cannot be created with elixir/ecto mix

MyWebApp-dev |   (elixir) lib/calendar/datetime.ex:537: DateTime.to_unix/2
MyWebApp-dev |   (elasticsearch) lib/elasticsearch/indexing/index.ex:287: Elasticsearch.Index.build_name/1
MyWebApp-dev |   (elasticsearch) lib/elasticsearch/indexing/index.ex:31: Elasticsearch.Index.hot_swap/2
MyWebApp-dev |   (elasticsearch) lib/mix/elasticsearch.build.ex:86: Mix.Tasks.Elasticsearch.Build.build/3
MyWebApp-dev | 
MyWebApp-dev | ** (Mix) Index products could not be created.
MyWebApp-dev | 
MyWebApp-dev |     %HTTPoison.Error{id: nil, reason: :econnrefused}

All the while, I can connect to the elasticsearch server:

A68MD-PRO:~# curl http://localhost:9200/_cat/health
1557359160 23:46:00 docker-cluster green 2 2 2 1 0 0 0 0 - 100.0%

Even from the container inside, curling yields:

A68MD-PRO:~# docker exec elasticsearch curl http://elasticsearch:9200/_cat/health
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    66  100    66    0     0   6969      0 --:--:-- --:--:-- --:--:--  7333
1557373042 03:37:22 docker-cluster green 2 2 2 1 0 0 0 0 - 100.0%

Does anyone know what this problem is about and how to solve it?

Not sure but at least I'd put the kibana instance in the same network as elasticsearch:

  kibana:
    image: docker.elastic.co/kibana/kibana:7.0.1
    ports:
      - "5601:5601"
    container_name: kibana
    networks:
      - esnet

Here is a typical one I'm using:

---
version: '3'
services:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:$ELASTIC_VERSION
    environment:
      - bootstrap.memory_lock=true
      - discovery.type=single-node
      - cluster.name=elasticsearch
      - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
      - cluster.routing.allocation.disk.threshold_enabled=false
      - xpack.license.self_generated.type=trial
      - xpack.security.enabled=$ELASTIC_SECURITY
      - ELASTIC_PASSWORD=$ELASTIC_PASSWORD
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
      - 9300:9300
    networks: ['stack']

  kibana:
    image: docker.elastic.co/kibana/kibana:$ELASTIC_VERSION
    environment:
      - ELASTICSEARCH_USERNAME=elastic
      - ELASTICSEARCH_PASSWORD=$ELASTIC_PASSWORD
    ports: ['5601:5601']
    networks: ['stack']
    links: ['elasticsearch']
    depends_on: ['elasticsearch']

networks:
  stack: {}

HTH

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.