# Kibana docker image doesn't connect to elasticsearch image

**URL:** <https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511>\
**Category:** Kibana\
**Created:** [March 21, 2017, 9:44pm UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511 "2017-03-21T21:44:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Woodford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woodford/32/9540_2.png) [@Woodford](https://discuss.elastic.co/u/Woodford)\
**Post date:** [March 21, 2017, 9:44pm UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/1 "2017-03-21T21:44:25Z")

</div>

I was able to run elasticsearch docker image, and login and/or change default passwords.

This is the run command from the docs:  
docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1” [docker.elastic.co/elasticsearch/elasticsearch:5.2.2](http://docker.elastic.co/elasticsearch/elasticsearch:5.2.2)

Kibana docker image doesn't connect with defaults (no options), and any env vars I try to set in the command line don't seem to be used, as the logs show: Unable to connect to Elasticsearch at [http://elasticsearch:9200](http://elasticsearch:9200) instead of my localhost:9200

Please help with the kibana docker run command to start kibana and connect to localhost:9200

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [March 22, 2017, 2:35pm UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/2 "2017-03-22T14:35:38Z")

</div>

Can you try providing a custom kibana.yml file like it's detailed here?  
[https://www.elastic.co/guide/en/kibana/current/\_configuring\_kibana\_on\_docker.html](https://www.elastic.co/guide/en/kibana/current/_configuring_kibana_on_docker.html)

Only line that you need in it should be:  
`elasticsearch.url: "http://localhost:9200"`

---

<div class="post-metadata">

**Author:** ![Woodford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woodford/32/9540_2.png) [@Woodford](https://discuss.elastic.co/u/Woodford)\
**Post date:** [March 23, 2017, 2:37am UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/3 "2017-03-23T02:37:33Z")

</div>

Thanks for the helpful reply Marius!

I can try that, and since I plan to deploy on AWS it requires several steps that I would prefer to avoid.

For example, I would have to create the file, host it somewhere (github), then when I create the host that I'm going to run docker on, I'd have to copy it to the host.

I suppose I could eliminate the storage and create the file with a command when I create the EC2, but still this requires several steps I'd like to avoid.

I think it's reasonable that Elastic provide the command to run Kibana and connect to the Elasticsearch cluster that's running with the parameters they provided.

---

<div class="post-metadata">

**Author:** ![jarpy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jarpy/32/51290_2.png) [@jarpy](https://discuss.elastic.co/u/jarpy)\
**Post date:** [March 23, 2017, 11:24pm UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/4 "2017-03-23T23:24:26Z")

</div>

Hi. This one is all about [Docker Networking](https://docs.docker.com/engine/userguide/networking/).

There are some steps involved in getting Docker to establish network links and name resolution between containers. It's one of the reasons I tend to recommend getting started with Docker Compose, since it takes care of some of these details.

The Kibana image tries, by default, to connect to a host/container called `elasticsearch`. However, the Docker operator must arrange for that name to make sense, and for there to be a network connection between the two containers. The latest, and probably simplest technique that Docker provides for this is "[user-defined networks](https://docs.docker.com/engine/userguide/networking/#user-defined-networks)".

Here is a minimal, working example of using user-defined networks with `docker run`:

```auto
docker network create elastic
docker run --network=elastic --name=elasticsearch docker.elastic.co/elasticsearch/elasticsearch:5.2.2
docker run --network=elastic -p 5601:5601 docker.elastic.co/kibana/kibana:5.2.2

```

Here, we create a user-defined network, ensure that both containers are attached to it, and crucially, make sure that the Elasticsearch container is named `elasticsearch`, just as Kibana expects. Docker will then ensure that the hostname `elasticsearch` resolves to the correct IP address for any container on that network.

If we don't do any of that, then Docker places the containers on the "default bridge network". From their documentation:

> Docker does not support automatic service discovery on the default bridge network. If you want to communicate with container names in this default bridge network, you must connect the containers[...]

Also note that trying to refer to the Elasticsearch container as `localhost` won't work either. Every container thinks that it is, itself, `localhost`. When you are inside the Kibana container, `localhost` actually _is_ the Kibana container.

Hopefully that helps to get you started. I highly recommend the [Docker Networking  
docs](https://docs.docker.com/engine/userguide/networking/) for more details and fancy tricks.

---

<div class="post-metadata">

**Author:** ![Woodford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woodford/32/9540_2.png) [@Woodford](https://discuss.elastic.co/u/Woodford)\
**Post date:** [March 24, 2017, 12:09am UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/5 "2017-03-24T00:09:25Z")

</div>

Hi Jarpy!

Thanks! This is what made the difference for me:

> [@jarpy](#):
>
> Also note that trying to refer to the Elasticsearch container as localhost won't work either. Every container thinks that it is, itself, localhost. When you are inside the Kibana container, localhost actually is the Kibana container.

Now that I realized the localhost issue, I changed my run command as follows and it worked.  
\> docker run -p 5601:5601 -e ELASTICSEARCH\_URL=http://my\_hostname:9200 [docker.elastic.co/kibana/kibana:5.2.2](http://docker.elastic.co/kibana/kibana:5.2.2)

Yes, I'll eventually start on docker networking (or swarm, or something). For now I just want to treat the containerized services as local services.

---

<div class="post-metadata">

**Author:** ![jarpy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jarpy/32/51290_2.png) [@jarpy](https://discuss.elastic.co/u/jarpy)\
**Post date:** [March 24, 2017, 12:25am UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/6 "2017-03-24T00:25:16Z")

</div>

Great! Glad I could help.

To make containers really "local-ish", you can also try `--net=host`, which will bind them directly to the physical NIC in the host machine. That will make `localhost` mean the same thing everywhere, and remove the need to map ports with `-p`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 21, 2017, 12:25am UTC](https://discuss.elastic.co/t/kibana-docker-image-doesnt-connect-to-elasticsearch-image/79511/7 "2017-04-21T00:25:20Z")

</div>

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