Just like everything else, ElasticSearch can also be dockerized.
- Create the docker-compose
- Get the containers for ElasticSearch and Kibana up and running
- Health check with
- Kibana Console UI
- curl Command
- Create a simple document
- Perform insertion, updatation, retreival and deletion.
To begin with, we will be creating a docker-compose file which will bring up ElasticSearch running in single node configuration.
version: "3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.2
container_name: elasticsearch
environment:
- discovery.type=single-node
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
labels:
- co.elastic.logs/module=elasticsearch
- co.elastic.metrics/module=elasticsearch
kibana:
image: docker.elastic.co/kibana/kibana:7.14.2
container_name: kibana
ports:
- 5601:5601
depends_on:
- elasticsearch
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
networks:
- elastic
networks:
elastic:
driver: bridge
volumes:
esdata:
driver: local
- The line pulls the ElasticSearch image of version 7.14.2
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.2
- Custom name for the container.
container_name: elasticsearch
- To run in single node, we set the container environment.
environment: - discovery.type=single-node
- To maintain persistancy of data on restarting the container and to not loose the data,
we create a host volume esdata and a container volume
/usr/share/elasticsearch/data. Host Volume will maintain the data for multiple restarts of
the container.
volumes: - esdata:/usr/share/elasticsearch/data
- Elasticsearch will use port 9200 for requests.
ports: - 9200:9200
- To maintain the security from the other networks in docker we have created a common
network for both kibana and elasticsearch
networks: - elastic
- We have to use the same version of kibana as elasticsearch
image: docker.elastic.co/kibana/kibana:7.14.2
- Custom name for the container.
container_name: kibana
- Kibana will connect to the container of elasticsearch with this service name and port.
yaml environment: ELASTICSEARCH_URL: http://elasticsearch:9200 ELASTICSEARCH_HOSTS: http://elasticsearch:9200
- This property tells Kibana service to run after the ElasticSearch container is up.
depends_on: - elasticsearch
- Kibana will use port 9200 for visualising the elasticsearch
ports: - 5601:5601
Lets execute the docker-compose.yml to bring up ElasticSearch and Kibana containers.
docker-compose --compatibility up