Skip to content
Apache Kafka introduction 2 min read

Running Kafka Locally

There are two convenient ways to run Kafka on your machine: a single-container Docker setup in KRaft mode, or a downloaded binary distribution. Both give you a working single-broker cluster in minutes. Modern Kafka (3.x and 4.x) uses KRaft, so you no longer need to run a separate ZooKeeper process.

Option A: Docker in KRaft mode

The official apache/kafka image runs a self-contained broker that acts as both controller and broker — no ZooKeeper required.

docker run -d --name kafka \
  -p 9092:9092 \
  apache/kafka:3.8.0

That single command starts a broker listening on localhost:9092. For a reproducible setup, use Compose:

services:
  kafka:
    image: apache/kafka:3.8.0
    ports:
      - "9092:9092"
    environment:
      KAFKA_NODE_ID: 1
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
      KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
docker compose up -d

The KAFKA_PROCESS_ROLES: broker,controller setting is what enables KRaft mode — the same node serves both roles, ideal for local development.

Option B: Download the binary

Grab a release from kafka.apache.org/downloads, extract it, then bootstrap a KRaft cluster:

tar -xzf kafka_2.13-3.8.0.tgz
cd kafka_2.13-3.8.0

# Generate a cluster ID and format the storage directory
KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
bin/kafka-storage.sh format -t "$KAFKA_CLUSTER_ID" \
  -c config/kraft/server.properties

# Start the broker
bin/kafka-server-start.sh config/kraft/server.properties

The broker logs started (kafka.server.KafkaRaftServer) once it is ready.

Creating your first topic

The CLI tools live under bin/ (or run them inside the container with docker exec). Create a topic named orders with three partitions:

bin/kafka-topics.sh --create \
  --topic orders \
  --partitions 3 \
  --replication-factor 1 \
  --bootstrap-server localhost:9092

Output:

Created topic orders.

On a single-broker cluster the replication factor must be 1 — you cannot replicate beyond the number of available brokers. Use 3 in production clusters.

List topics to confirm, then describe one to see its partition layout:

bin/kafka-topics.sh --list --bootstrap-server localhost:9092
bin/kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092

Output:

Topic: orders   PartitionCount: 3   ReplicationFactor: 1
   Topic: orders   Partition: 0   Leader: 1   Replicas: 1   Isr: 1
   Topic: orders   Partition: 1   Leader: 1   Replicas: 1   Isr: 1
   Topic: orders   Partition: 2   Leader: 1   Replicas: 1   Isr: 1

If you ran Kafka via Docker, prefix these commands with docker exec kafka /opt/kafka/bin/kafka-topics.sh .... You now have a running broker and a topic — the next pages dig into how topics, partitions, producers, and consumers work together.

Last updated June 1, 2026
Was this helpful?