How to Setup ELK Stack in Docker: Step-by-Step Guide
ELK Stack Series

Setup ELK Stack in Docker to simplify log management without the hassle of manual installations. In this guide, we’ll walk through containerizing Elasticsearch, Logstash, and Kibana using Docker Compose — so you can spin up a fully working ELK Stack in minutes and start collecting, processing, and visualizing logs right away.
Introduction: Observability with ELK Stack
Observability is the backbone of any reliable, production-grade application. Without proper logging, debugging issues in distributed systems or microservices becomes nearly impossible. This is where the ELK Stack — Elasticsearch, Logstash, and Kibana — comes in.
We’ve already covered the fundamentals in detail in our earlier post: What is the ELK Stack? Master Elasticsearch, Logstash, and Kibana with Real-World Examples. If you’re new to ELK, you can go through it later. For everyone else, here’s a quick recap.
Our application, or our microservices, generate logs. These logs can be written into log files. Then, Logstash collects or reads these logs, processes and transforms them if required, and sends them to Elasticsearch. Elasticsearch stores and indexes these logs, making them easy to search and analyze. And finally, we use Kibana to visualize and monitor these logs through dashboards and a user-friendly interface.
So, in simple terms, our flow looks like this:
In this post, we’ll integrate our Loyalty Application with the ELK Stack using Docker — giving you a real, working example instead of just theory.
Loyalty Application
What is a Loyalty Application?
A loyalty application is used to manage customer loyalty. It’s a common building block in e-commerce and retail systems, and a great real-world candidate for demonstrating observability, since it involves multiple transactional flows worth logging and monitoring.
The basic flow of our application is:
- First, we register a customer.
- Once the customer is registered, we can provide some loyalty points to the customer’s wallet.
- The customer can then use or redeem those loyalty points while making a purchase.
- And if required, the redeemed points can also be refunded.
This gives us a simple but realistic transaction flow that we can use to demonstrate application logging.
Loyalty Application API
Customer APIs
The first category is Customer APIs. We have APIs for creating a customer and performing the basic CRUD operations on the customer.
- Create Customer
- Get Customer
- Get All Customers
- Update Customer
- Delete Customer
- Activate Customer
- Deactivate Customer
Transaction APIs
- Earn Point
- Redeem Point
- Refund Point
- Get Transactions
(Postman collection link goes here)
API Sequence Flow
1. Create Customer
Registers a new customer in the system. The request first passes through validation — if the email already exists, the flow short-circuits with a 409 Conflict; otherwise, the customer is persisted and a 201 Created response is returned.
2. Earn Points
Credits loyalty points to a customer’s wallet. The system first verifies the customer exists and is active — if not found, it returns a 404; otherwise, the points are credited and the wallet balance is updated.
3. Redeem Points
Deducts loyalty points from a customer’s wallet during a purchase. The system verifies the customer exists and has sufficient balance — if the customer isn’t found, it returns a 404; if the balance is too low, a 400; otherwise, points are debited and the transaction completes.
4. Refund Points
Reverses a previous redemption and credits the points back to the customer’s wallet. The system verifies the customer, confirms the original redemption transaction exists, and checks it hasn’t already been refunded — before crediting the points back.
