How to run ZooKeeper and Kafka in Docker

Natthapon Pinyo
1 min readNov 24, 2020

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

$ docker network create app-tier --driver bridge

This step is to create Docker Network named app-tier

Step 2 — Launch ZooKeeper container

$ docker run -d --name zookeeper --network app-tier -p 2181:2181 -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper

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

$ docker run -d --name kafka --network app-tier --hostname localhost -p 9092:9092 -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 bitnami/kafka

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 :)

--

--