Kibana on Docker cannot connect to Elasticsearch Kibana on Docker cannot connect to Elasticsearch elasticsearch elasticsearch

Kibana on Docker cannot connect to Elasticsearch


There is some misunderstanding about what localhost or 127.0.0.1 means when running a command inside a container. Because every container has its own networking, localhost is not your real host system but either the container itself. So when you are running kibana and pointing the ELASTICSEARCH_URL variable to localhost:9200 the kibana process will look for elasticsearch inside the kibana container which of course isn't running there.

You already introduced some custom network that you referenced when starting the containers. All containers running in the same network can reference each other via name on their exposed ports (see Dockerfiles). As you named your elasticsearch container elasticsearch_2_4, you can reference the http endpoint of elasticsearch as http://elasticsearch_2_4:9200.

docker run -d --network mynetwork -e ELASTICSEARCH_URL=http://elasticsearch_2_4:9200 -p 5601:5601 kibana:4.6

As long as you don't need to access the elasticsearch instance directly, you can even omit mapping the ports 9200 and 9300 to your host.

Instead of starting all containers on their own, I would also suggest to use docker-compose to manage all services and parameters. You should also consider mounting a local folder as volume to have the data persisted. This could be your compose file. Add the networks, if you need to have the external network, otherwise this setup just creates a network for you.

version: "2"services:  elasticsearch:    image: elasticsearch:2.4    ports:      - "9200:9200"    volumes:      - ./esdata/:/usr/share/elasticsearch/data/  kibana:    image: kibana:4.6    ports:      - "5601:5601"    environment:      - ELASTICSEARCH_URL=http://elasticsearch:9200


Test:

docker run -d -e ELASTICSEARCH_URL=http://yourhostip:9200 -p 5601:5601 kibana:4.6

You can test with your host ip or the ip identified by docker0 in ifconfig

Regards


I changed network configuration for Kibana container and after this it works fine:

Kitematic Kibana Settings[1]