In this section, we will set up Elasticsearch and Kibana using Docker. This setup is intentionally kept simple so that you can focus on understanding Elasticsearch concepts rather than spending time on complex infrastructure issues.
Important Ports Used by Elasticsearch and Kibana
Before running anything, it is important to understand the ports involved.
Elasticsearch Ports
- Port 9200
This is the main HTTP port used by clients to interact with Elasticsearch.
You will use this port for:- CRUD operations
- Search queries
- Index management
- Port 9300
This port is used for internal communication between Elasticsearch nodes.
It is required for clustering, high availability, and scalability.
We will explore this in more detail later in the course.
Kibana Port
- Port 5601
This is the web interface for Kibana.
You access it through your browser to visually interact with Elasticsearch.
Why Use Kibana?
Although Elasticsearch exposes powerful REST APIs, working directly with raw API calls can sometimes feel overwhelming, especially when learning.
Kibana provides a clean and intuitive user interface that makes interaction with Elasticsearch easier and more visual.
docker compose file
# Security has been disabled for simplicity during learning.
# Don't worry, security will be covered later in this course.
services:
elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.2
ports:
- 9200:9200
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- xpack.security.http.ssl.enabled=false
kibana:
image: docker.elastic.co/kibana/kibana:9.0.2
ports:
- 5601:5601
environment:
- ELASTICSEARCH_HOSTS=http://elastic:9200
Before running anything, let’s understand what is inside the docker-compose.yml file.
Services Defined in Docker Compose
There are two services in this setup:
1. Elasticsearch Service
- Uses the official Elasticsearch Docker image.
- The version might change over time, but the course repository always contains a stable and tested version.
- The image is periodically updated, so you do not need to worry about minor version changes.
Key configurations include:
- Port mapping (9200:9200) so external applications (like Spring Boot) can connect.
- Single-node setup, meaning:
- No clustering.
- Easier learning experience.
- Security disabled temporarily to reduce complexity during learning.
2. Kibana Service
- Uses the official Kibana Docker image.
- Exposes port 5601 to access the UI in the browser.
- Needs to communicate with Elasticsearch.
Important detail:
Kibana does not use localhost to connect to Elasticsearch.
Instead, it uses the Docker service name, because both services run inside the same Docker network.
This is a very important concept in Docker-based networking.
Starting Elasticsearch and Kibana
Open your terminal and navigate to the directory of the file docker-compose.yml
Now run:
docker compose up
(or docker-compose up, both work depending on your Docker version)
What Happens Next
- Docker will start pulling the required images if they are not already available.
- This may take some time on the first run.
- Elasticsearch takes a bit longer to start because it performs internal initialization.
- Kibana waits until Elasticsearch becomes available.
Be patient during this step.
How to Access Elasticsearch
Using the Browser
Open:
http://localhost:9200
You should see a JSON response similar to:
{
"name" : "some-node",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "...",
"version" : {
"number" : "9.0.2"
},
"tagline" : "You Know, for Search"
}
This confirms:
- Elasticsearch is running
- Port mapping works
- Your system can communicate with it
How to Access Kibana
Open your browser and go to:
http://localhost:5601
You should see the Kibana UI.
Important Note About Docker Networking
You might wonder:
Why does Kibana use
http://elastic:9200instead ofhttp://localhost:9200?
Explanation:
localhostrefers to inside the container itselfelasticis the Docker service name- Docker automatically creates an internal network
- Containers communicate using service names
This is why:
ELASTICSEARCH_HOSTS=http://elastic:9200
works perfectly.
