Skip to main content
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

PlatformInstallation
MacDocker Desktop for Mac
WindowsDocker Desktop for Windows
LinuxDocker 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
FileConfiguration
zk-single-kafka-single.ymlOne ZooKeeper, one broker (learning)
zk-single-kafka-multiple.ymlOne ZooKeeper, multiple brokers
zk-multiple-kafka-multiple.ymlMultiple ZooKeeper, multiple brokers
Step 3: Start the cluster
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 ConduktorConduktor Console can connect to your Docker-based Kafka cluster at localhost:9092 for visual management of topics and messages.

Next steps