Elasticsearch and Kibana on Docker
ElasticSearch and Kibana on Docker
Learn how to run Elasticsearch and basics of Elasticsearch alongside with its visualisation tool Kibana, and how to connect both of them in a docker network.
Pre-requisite
Docker should be installed on your machine.
Checkout my blog how to get started with docker Getting started with Docker
ElasticSearch Installation
Elasticsearch is a distributed, RESTful search and analytics engine used for full-text search and log data analysis.
To install elastic search first we will create docker network.
docker network create elastic
Once elastic network is created in docker we will deploy the elastic search image with these flags.
docker run --name es01 --net elastic -p 9200:9200 -it -m 500MB docker.elastic.co/elasticsearch/elasticsearch:8.10.4
--name to give our container name
--net to deploy on elastic network
-p for exposing container port to host
-it for interactive terminal
-m to allocate storage for the container
Once The cluster is started we can get these details about cluster on our terminal.
export the password in environment variable to the value
export ELASTIC_PASSWORD=<password-on-elastic-container-log>
Copy the certificate from inside the container so that when we try to communicate with the cluster through its API it will be a secure communication
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
Copy the Enrollment Token as well as paste somewhere it will be used in kibana installation
Now to test the cluster we can use the command to check health and details about cluster
curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD -X GET "https://localhost:9200/_cluster/health"
Kibana Installation
Kibana is an open-source data visualisation and exploration tool that works in conjunction with Elasticsearch used for visualising and analysing data stored in Elasticsearch.
To install Kibana we can run this docker command
docker run --name kib01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.10.4
--name for naming kibana container
--net to deploy it on elastic network which we created
-p for port mapping to expose the container on localhost
Copy the address from terminal and paste it in your browser.
Copy the Enrollment token from elasticsearch container which is shown above and paste on kibana page to go into login page
Enter username and password.
username is elastic
password can be obtained from elasticsearch container as shown in above section.
Now Kibana is successfully connected with your ElasticSearch instance.
To test whether it is connected with elastic search, On your left screen side, open the hamburger menu and navigate to Dev tools in Management section.
You can Now enter elastic search query in the fields. One example is shown below
In this tutorial we learned how to setup Elastic Search and kibana on Docker. Keep following the devopshere blog to learn more about devops.