1
votes

I am looking for a working version of a docker-compose file that starts up kibana and elasticsearch together on docker for mac at version 7.3.2. I've followed the most recent instructions on kibana and elasticsearch's 7.3.2 documentation and my docker-compose.yml file below is the union of what I gathered from both docs. (The kibana doc was the most vague with respect to the docker compose config). I've also tried following other stack overflow articles (written for older versions) but they don't seem to work with the latest versions. I now suspect I'm missing something version specific. 7.3.1 didn't work with the same config either.

I should note that the elasticsearch portion of the file works fine; I can hit http://localhost:9200 and I get a json response. However Kibana's url (http://localhost:5601) returns Kibana server is not ready yet with this error:

kibana | {"type":"log","@timestamp":"2019-09-12T21:45:04Z","tags":["warning","elasticsearch","admin"],"pid":7,"message":"Unable to revive connection: http://elasticsearch:9200/"}

This is my best attempt so far:

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.3.2
    container_name: es01
    environment:
      - node.name=es01
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,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.3.2
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,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:
    container_name: kibana
    image: docker.elastic.co/kibana/kibana:7.3.2
    ports:
      - 5601:5601
    networks:
      - esnet  
    environment:
      SERVER_NAME: kibana.example.org
      ELASTICSEARCH_URL: http://elasticsearch:9200

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

networks:
  esnet:
3
Nothing in your environment has a host name elasticsearch. The service names es01 and es02 are both usable as host names, though.David Maze
Thanks David. I was experimenting further just now and switched out ELASTICSEARCH_URL with ELASTICSEARCH_HOSTS and specified es01 and it worked! Was the switch from URL to HOSTS also necessary?Damon
@DavidMaze Id be happy to accept your comment as the answer if you want to post it as an answer. It would be good to clarify whether ELASTICSEARCH_URL or ELASTICSEARCH_HOSTS is the right setting as well if you know. I went with ELASTICSEARCH_HOSTS and that seems to be working.Damon

3 Answers

0
votes

Docker Compose automatically creates a private Docker network for you, and within that, the names of the service: blocks are valid hostnames.

When you set

ELASTICSEARCH_URL: http://elasticsearch:9200

None of your containers are named elasticsearch so the hostname lookup fails, but if you pick either node es01 or es02 it will work

ELASTICSEARCH_URL: http://es01:9200

(Note that you don’t explicitly need a networks: definition for this to work, Compose will create a network named default for you. You also don’t need to explicitly set container_name: unless you’re planning on trying to manage the same containers with non-Compose tooling.)

0
votes

Use ELASTICSEARCH_HOSTS: http://es01:9200 instead of ELASTICSEARCH_URL to update the environment from the docker-compose.yml file. Here is the Elasticsearch documentation about environment variable configuration https://www.elastic.co/guide/en/kibana/current/docker.html#environment-variable-config.

0
votes

You need to add network configuration also in kibana service like
networks:
- esnet

and in ELASTICSEARCH_HOST: http://es01:9200

note es01 is your container name