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. 🚀

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay