DEV Community

Cover image for Apache Kafka with Docker
Zahid Ahmed
Zahid Ahmed

Posted on

Apache Kafka with Docker

Apache Kafka, a robust distributed streaming platform, is essential for building dynamic data pipelines and real-time applications. Pairing it with Docker makes setting up Kafka seamless, empowering developers to explore and innovate effortlessly. In this guide, we’ll dive into the step-by-step process of running Apache Kafka with Docker

Create Docker Compose File

https://github.com/zahido/Docker.git
Enter fullscreen mode Exit fullscreen mode

This docker-compose.yml file contains kafka, zookeeper & GUI redpanda.

Spin Docker Compose

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Verify Container is Running

docker ps
Enter fullscreen mode Exit fullscreen mode

Create Topic

docker exec -it <kafka-container-id> /opt/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic my-topic
Enter fullscreen mode Exit fullscreen mode

Replace with the actual container ID of the Kafka container (you can find it using docker ps).

Produce & Consume Messages

docker exec -it <kafka-container-id> /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning
Enter fullscreen mode Exit fullscreen mode

Replace with the actual container ID of the Kafka container.

You’ve successfully set up and run Apache Kafka on Docker well done! This guide offers you a straightforward yet effective way to experiment with Kafka. 🚀

Top comments (0)