In this article, we will explore how to deploy Elasticsearch and Kibana using Docker Compose. These are two key components of the ELK Stack (Elasticsearch, Logstash, Kibana), helping you search, analyze, and visualize data effectively. Below are the detailed configurations and how each component works.
1. Elasticsearch
a. Basic Configuration
Elasticsearch is configured to run in a Docker container with the following parameters:
-
Image: The official Elasticsearch image, version
8.17.2
, is used. -
Single-node mode: Enabled via the environment variable
discovery.type=single-node
. -
Security: X-Pack security is enabled (
xpack.security.enabled=true
), and the password for theelastic
user is set toYVG6PKplG6ugGOw
. -
Network: Elasticsearch listens on all network interfaces (
network.host=0.0.0.0
). -
JVM Memory: Configured with
-Xms1g
(initial memory) and-Xmx1g
(maximum memory).
b. Ports and Volumes
-
Ports: Port
9200
(HTTP) and9300
(internal communication) are mapped from the container to the host. -
Volumes: Elasticsearch data is stored in the
elasticsearch-data
volume.
c. Healthcheck
A healthcheck is set up to monitor Elasticsearch's status by calling the /_cluster/health
API with the elastic
user. If the API fails to respond, the container will restart.
2. Kibana
a. Basic Configuration
Kibana is configured to connect to Elasticsearch and run in a Docker container with the following parameters:
-
Image: The official Kibana image, version
8.17.2
, is used. -
Elasticsearch Connection: The Elasticsearch address is set to
http://elasticsearch:9200
. -
Authentication: Kibana uses the
kibana_user
with the passwordYVG6PKplG6ugGOw
to connect to Elasticsearch.
b. Ports and Networks
-
Ports: Port
5601
is mapped from the container to the host to access the Kibana interface. -
Networks: Kibana is connected to the
elk-network
.
c. Dependency on Elasticsearch
Kibana only starts after Elasticsearch is ready, ensuring a successful connection between the two services.
3. Volume and Network
a. Volume
-
elasticsearch-data: This volume is used to store Elasticsearch data, ensuring data persistence even if the container is deleted.
b. Network
-
elk-network: A
bridge
network is created to connect Elasticsearch and Kibana services.
4. How to Use
a. Starting the Services
To start Elasticsearch and Kibana, run the following command:
b. Creating a Kibana User (If Needed)
If you want to use a dedicated user for Kibana, you can create one with the following command:
To use a token instead of a password, you can create one with the following command:
5. Troubleshooting
-
If you encounter errors, you can check the container logs using:
-
To restart Kibana:
Full Content of the Docker Compose File
Below is the full content of the docker-compose-els.yml
file:
Conclusion
With this Docker Compose configuration, you can easily deploy Elasticsearch and Kibana to serve your data search, analysis, and visualization needs. Customize and extend this configuration to fit the specific requirements of your project!