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

This entry is part 2 of 2 in the series ELK Stack Series

ELK Stack Series

ELK Stack Diagram: Logs from applications collected by Logstash, stored in Elasticsearch, and visualized with Kibana.

What is the ELK Stack? Master Elasticsearch, Logstash, and Kibana with Real-World Examples

Set up ELK Stack in Docker showing Logstash, Elasticsearch, and Kibana pipeline for centralized log management

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

ELK Stack setup in Docker showing Logstash, Elasticsearch, and Kibana pipeline for centralized log management
Setting up the ELK Stack (Elasticsearch, Logstash, Kibana) using Docker for efficient log management.

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:

ELK Stack log pipeline Three apps write log files that merge into Logstash, flow to Elasticsearch, into Kibana, then are searched. App 1 App 2 App 3 app1.log app2.log app3.log Logstash Collect, filter Elasticsearch Store, index Kibana Dashboards Search and analyze Application → Log File → Logstash → Elasticsearch → Kibana

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 transaction flow with wallet balance Sequence showing customer registration, point earning, point redemption, and point refund, with wallet balance changing at each step. 1. Register customer 2. Earn points +4,000 pts 3. Redeem points -800 pts 4. Refund points +800 pts Wallet created 0 pts 0 + 4,000 4,000 pts 4,000 – 800 3,200 pts 3,200 + 800 4,000 pts Register → Earn → Redeem → Refund

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.

  1. Create Customer
  2. Get Customer
  3. Get All Customers
  4. Update Customer
  5. Delete Customer
  6. Activate Customer
  7. Deactivate Customer

Transaction APIs

  1. Earn Point
  2. Redeem Point
  3. Refund Point
  4. 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.

ELK Stack Series

What is the ELK Stack? Master Elasticsearch, Logstash, and Kibana with Real-World Examples

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *