Setup Kafka Zookeeper in Docker

Setting up Apache Kafka and Zookeeper in docker is easy thanks to popular DockerFiles like wurstmeister/kafka-docker. Let’s go through a quick setup of Kafka and Zookeeper in docker on a single node system.


  • Linux System
  • Git
  • Docker
  • Docker-compose

Kafka and Zookeeper

Start by cloning the repo:

git clone

Then change to the kafka-docker directory:

cd kafka-docker

Now let’s edit the docker-compose.yml file. Change the Kafka Advertised Hostname to localhost:


Expose the Kafka port to the system so that apps outside of the docker network can talk to it:

    build: .
      - "9092:9092"

Finally, under the Kafka environment variables, add any topics that you want Kafka to automatically create:


The first number after the topic refers to the partition, and the second number refers to the replica set. Save that file and build the containers with docker-compose.

sudo docker-compose up --build -d

You should now see both containers running by using the docker ps command.

docker ps

That’s it! You now have Apache kafka and zookeeper in docker running on your system.

See also