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
Kafka and Zookeeper
Start by cloning the repo:
git clone https://github.com/wurstmeister/kafka-docker
Then change to the kafka-docker directory:
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:
kafka: build: . ports: - "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.
That’s it! You now have Apache kafka and zookeeper in docker running on your system.