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.

By Stéphane Derosiaux · Updated October 16, 2026

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 the Docker Compose plugin if your Docker Engine doesn't have it yet.

Run Kafka with Docker Compose

Docker Compose runs multi-container applications from a single file. Here it runs one Kafka broker in KRaft mode, using the official apache/kafka image: no ZooKeeper container is needed.

Step 1: Create the Compose file

Create a folder, and save this as docker-compose.yml inside it:

services:
  kafka:
    image: apache/kafka:4.3.1
    container_name: kafka
    ports:
      - "9092:9092"

The image's default settings start a single-node cluster that clients on your machine reach at localhost:9092. To switch Kafka versions, change the image tag.

Step 2: Start the cluster

From that folder, run:

docker compose up -d

Step 3: Verify the cluster

docker compose ps

Expected output:

NAME      IMAGE                COMMAND                  SERVICE   CREATED         STATUS         PORTS
kafka     apache/kafka:4.3.1   "/__cacert_entrypoin…"   kafka     8 seconds ago   Up 8 seconds   0.0.0.0:9092->9092/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

The Kafka scripts live in /opt/kafka/bin inside the container:

docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

Option 2: Run from your host machine

Install the Kafka binaries on your system (skip the steps for formatting storage and starting Kafka):

  • Mac (follow the whole document except formatting storage and starting Kafka)
  • Linux (follow the whole document except formatting storage and starting Kafka)
  • Windows (follow the whole document except formatting storage and starting Kafka)

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 stop

Remove containers and network (removes data):

docker compose down

See it in practice with Conduktor

Conduktor Console can connect to your Docker-based Kafka cluster at localhost:9092 for visual management of topics and messages.

Next steps