How to run ZooKeeper and Kafka in Docker

There are so many Docker images for Kafka and ZooKeeper.

One of the most popular Docker Image is Bitnami/kafka

From an official document, just few steps to do it.

Basically we need to create Docker Network to be a bridged between ZooKeeper and Kafka Docker Containers.

Step 1 — Create Docker Network

This step is to create Docker Network named app-tier

Step 2 — Launch ZooKeeper container

This step is to create Docker Container from bitnami/zookeeper inside Docker Network app-tier with port mapping 2181 to localhost 2181

Step 3 — Launch Kafka container

This step is to create Docker Container from bitnami/kafka inside Docker Network app-tier with port mapping 9092 to localhost 9092 and connect to zookeeper container in the same Docker Network

You can check running Docker Instance from Docker Dashboard

Docker Dashboard

To connect Kafka, you can point you application config to localhost:9092

That’s it! Happy coding :)

Java Team Leader at Aware Group