docker-compose.yml for elasticsearch and kibana docker-compose.yml for elasticsearch and kibana docker docker

docker-compose.yml for elasticsearch and kibana


To add the hard dependency on elasticsearch for kibana, you need the depends_on variable to be set as shown below. Also, to add to @Phil McMillan's answer, you can set the elasticsearch_url variable in kibana, without static addressing using Docker's inbuilt DNS mechanism.

version: '2.1'services:     elasticsearch:       image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3       container_name: elasticsearch       networks:           docker-elk:     kibana:       image: docker.elastic.co/kibana/kibana:5.4.3       container_name: kibana       environment:          - "ELASTICSEARCH_URL=http://elasticsearch:9200"       networks:          - docker-elk       depends_on:          - elasticsearchnetworks:  docker-elk:    driver: bridge

Note the environment variable ELASTICSEARCH_URL=http://elasticsearch:9200 just uses has the container name (elasticsearch) which the Docker DNS server is able to resolve.


You need to include the links.

version: "2.0"services:  elasticsearch:    image: elasticsearch:latest    ports:      - "9200:9200"      - "9300:9300"    networks:      - docker_elk  kibana:    image: kibana:latest    ports:      - "5601:5601"    links:      - elasticsearch    networks:      - docker_elknetworks:  docker_elk:    driver: bridge

UPDATED

When using the image elasticsearch:latest, it's Elasticsearch 5.0 and requires us to increase our Docker host virtual memory.

Before running the docker-compose, please make sure to run this command on your Docker host.

Linux:

su rootsysctl -w vm.max_map_count=262144

Windows (boot2docker)

docker-machine ssh defaultsudo sysctl -w vm.max_map_count=262144

If you don't want to change your Docker host, just use the Elasticsearch 2.x image at elasticsearch:2


I have this working. No links are needed and it doesn't have anything to do with elasticsearch starting before kibana. The issue is that when running under compose, a new bridged network is defined with its own set of IPs. Kibana needs to communicate with the cluster over this bridged network - "localhost" is not available anymore for the connectivity.

You need to do a couple of things:

  1. You need to set a couple of values in kibana.yml or under the environment: section of kibana in the compose file):

a. elasticsearch.url in kibana.yml (or ELASTICSEARCH_URL under the environment: section of kibana in the compose file) must be set to the specific IP of the cluster and port 9200 - localhost will not work, as it does when you run outside of compose.

elasticsearch.url: "http://172.16.238.10:9200"

b. You also need to set server.host (SERVER_HOST) to the bridged IP of the Kibana container.

server.host: "172.16.238.12"  

Note: you still access the kibana UI from with http://127.0.0.1:5601 and you still need those "ports" commands!

  1. You need to set an "ipam" configuration under your bridged network and assign elasticsearch and kibana static ips so that kibana can access it via its configuration above.

Something like this should suffice:

elasticsearch:  networks:    esnet:      ipv4_address: 172.16.238.10kibana:  networks:    esnet:      ipv4_address: 172.16.238.12networks:  esnet:    driver: bridge    ipam:      driver: default      config:        - subnet: 172.16.238.0/24

Don't forget to use one of the documented methods to set Kibana configuration - ELASTICSEARCH_URL is required to be set!

I have a docker compose file that creates two elasticsearch nodes and a kibana instance all running on the same bridged network. It is possible.