27

I am trying to run use kibana console with my local elasticsearch (container) In the ElasticSearch documentation I see

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.2.2

Which lets me run the community edition in a quick one liner.

Looking at the kibana documentation i see only

docker pull docker.elastic.co/kibana/kibana:6.2.2

Replacing pull with run it looks for the x-pack (I think it means not community) and fails to find the ES

Unable to revive connection: http://elasticsearch:9200/

Is there a one liner that could easily set up kibana localy in a container? All I need is to work with the console (Sense replacement)

Bick
  • 17,833
  • 52
  • 146
  • 251

2 Answers2

62

If you want to use kibana with elasticsearch locally with docker, they have to communicate with each other. To do so, according to the doc, you need to link the containers. You can give a name to the elasticsearch container with --name:

docker run \
  --name elasticsearch_container \
  --publish 9200:9200 \
  --publish 9300:9300 \
  --env "discovery.type=single-node" \
  docker.elastic.co/elasticsearch/elasticsearch:6.2.2

And then link this container to kibana:

docker run \
  --name kibana \
  --publish 5601:5601 \
  --link elasticsearch_container:elasticsearch_alias \
  --env "ELASTICSEARCH_URL=http://elasticsearch_alias:9200" \
  docker.elastic.co/kibana/kibana:6.2.2

The port 5601 is exposed locally to access it from your browser. You can check in the monitoring section that elasticsearch's health is green.

EDIT (24/03/2020):

The option --link may eventually be removed and is now a legacy feature of docker. The idiomatic way of reproduce the same thing is to firstly create a user-defined bridge:

docker network create elasticsearch-kibana

And then create the containers inside it:

 Version 6

docker run \
  --name elasticsearch_container \
  --network elasticsearch-kibana \
  --publish 9200:9200 \
  --publish 9300:9300 \
  --env "discovery.type=single-node" \
  docker.elastic.co/elasticsearch/elasticsearch:6.2.2
docker run \
  --name kibana \
  --publish 5601:5601 \
  --network elasticsearch-kibana \
  --env "ELASTICSEARCH_URL=http://elasticsearch_container:9200" \
  docker.elastic.co/kibana/kibana:6.2.2

Version 7

As it was pointed out, the environment variable changed for the version 7. It now is ELASTICSEARCH_HOSTS.

docker run \
  --name elasticsearch_container \
  --network elasticsearch-kibana \
  --publish 9200:9200 \
  --publish 9300:9300 \
  --env "discovery.type=single-node" \
  docker.elastic.co/elasticsearch/elasticsearch:7.6.2
docker run \
  --name kibana \
  --publish 5601:5601 \
  --network elasticsearch-kibana \
  --env "ELASTICSEARCH_HOSTS=http://elasticsearch_container:9200" \
  docker.elastic.co/kibana/kibana:7.6.2

User-defined bridges provide automatic DNS resolution between containers that means you can access each other by their container names.

Community
  • 1
  • 1
L. Meyer
  • 2,863
  • 1
  • 23
  • 26
  • Why does ```--link elasticsearch:elasticsearch``` option is necessary? – meshkati May 28 '19 at 10:09
  • 1
    Just to be clearer, I differentiated the container name from the alias. As both container are isolated, they can't send information to each other, this option enables a sort of bridge between them. – L. Meyer May 28 '19 at 17:25
  • 2
    `ELASTICSEARCH_URL` env variable didn't work for me. I had to use `ELASTICSEARCH_HOSTS`. This is with Elasticsearch and Kibana version 7.6.2. Full example: `--env "ELASTICSEARCH_HOSTS=http://elasticsearch_container:9200"` – Johnny Oshika Apr 04 '20 at 16:25
5

It is convenient to use docker-compose as well.
For instance, the file below, stored in home directory, allows to start Kibana with one command:
docker-compose up -d:

# docker-compose.yml

version: "2"
 kibana:
    image: "docker.elastic.co/kibana/kibana:6.2.2"
    container_name: "kibana"
    environment:
      - "ELASTICSEARCH_URL=http://<elasticsearch-endpoint>:9200"
      - "XPACK_GRAPH_ENABLED=false"
      - "XPACK_ML_ENABLED=false"
      - "XPACK_REPORTING_ENABLED=false"
      - "XPACK_SECURITY_ENABLED=false"
      - "XPACK_WATCHER_ENABLED=false"
    ports:
      - "5601:5601"
    restart: "unless-stopped"

In addition, Kibana service might be a part of your project in development environment (in case, docker-compose is used).

antonbormotov
  • 1,821
  • 2
  • 20
  • 32
  • what are all the XPACK vars for? – Mugen Aug 14 '19 at 12:33
  • These variables set respective parameters in kibana.yml, see documentation here: https://www.elastic.co/guide/en/kibana/current/docker.html#environment-variable-config; Xpack is installed by default in the official docker image. – antonbormotov Aug 14 '19 at 13:06