How to start Kafka using Docker
Install Kafka with Docker on any OS. Run a single-broker KRaft cluster with Docker Compose, walk through the compose file, and verify the cluster is up.
Run Kafka on any operating system in five minutes
Docker provides the most portable way to run Kafka. It works identically on Mac, Windows, and Linux, and makes switching Kafka versions straightforward.
What you'll learn:
- How to run Kafka with Docker Compose
- How to execute Kafka commands against a Docker cluster
- How to manage your Docker-based Kafka environment
Install Docker
| Platform | Installation |
|---|---|
| Mac | Docker Desktop for Mac |
| Windows | Docker Desktop for Windows |
| Linux | Docker Engine (choose your distro) |
Docker Desktop on Mac and Windows includes Docker Compose. On Linux, install Docker Compose separately.
Run Kafka with Docker Compose
Docker Compose runs multi-container applications. Each Kafka component (ZooKeeper, broker) runs in a separate container.
Step 1: Clone the repository
git clone https://github.com/conduktor/kafka-stack-docker-compose.git
cd kafka-stack-docker-compose Step 2: Choose a configuration
| File | Configuration |
|---|---|
zk-single-kafka-single.yml | One ZooKeeper, one broker (learning) |
zk-single-kafka-multiple.yml | One ZooKeeper, multiple brokers |
zk-multiple-kafka-multiple.yml | Multiple ZooKeeper, multiple brokers |
docker-compose -f zk-single-kafka-single.yml up -d Step 4: Verify the cluster
docker-compose -f zk-single-kafka-single.yml ps Expected output:
Name Command State Ports
-------------------------------------------------------------------------------------------
kafka1 /etc/confluent/docker/run Up 0.0.0.0:9092->9092/tcp, 0.0.0.0:9999->9999/tcp
zoo1 /etc/confluent/docker/run Up 0.0.0.0:2181->2181/tcp, 2888/tcp, 3888/tcp Kafka is available at localhost:9092.
Run Kafka commands
You have two options for running Kafka CLI commands:
Option 1: Run inside the container
docker exec -it kafka1 /bin/bash Inside the container, run commands without the .sh extension:
kafka-topics --version Option 2: Run from your host machine
Install the Kafka binaries on your system (skip the steps for starting ZooKeeper and Kafka):
- Mac (follow the whole document except starting Kafka and ZooKeeper)
- Linux (follow the whole document except starting Kafka and ZooKeeper)
- Windows (follow the whole document except starting Kafka and ZooKeeper)
Then run commands with the .sh extension:
kafka-topics.sh --bootstrap-server localhost:9092 --list Stop and clean up
Stop containers (preserves data):
docker-compose -f zk-single-kafka-single.yml stop Remove containers and network (removes data):
docker-compose -f zk-single-kafka-single.yml down See it in practice with Conduktor
Conduktor Console can connect to your Docker-based Kafka cluster at
localhost:9092for visual management of topics and messages.
Next steps
- CLI tutorials to practice Kafka commands against your cluster
- Topics CLI tutorial to create and manage your first topics
- Kafka fundamentals to understand core concepts