Search code examples
dockerkibana

Running a local kibana in a container


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)


Solution

  • 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.