Install Confluent Kafka Using Docker Desktop (KRaft Mode)

Install Confluent Kafka: Apache Kafka is one of the most popular event streaming platforms used for building real-time applications, microservices communication, messaging systems, and data pipelines.

Confluent Kafka extends Apache Kafka by providing additional tools and services that simplify Kafka development and management.

Traditionally, Kafka required ZooKeeper for cluster management. However, modern Kafka deployments use KRaft (Kafka Raft Metadata Mode), which eliminates the need for ZooKeeper and simplifies the overall architecture.

Install Confluent Kafka KRaft Mode using Docker desktop

In this tutorial, you will learn how to install and run Confluent Kafka using Docker Desktop with a single command. You will also learn how to verify the installation by creating topics and exchanging messages between a producer and a consumer.

Prerequisites

Before proceeding, make sure you have:

Verify Docker installation

Open Command Prompt or Windows PowerShell, and run the command below:

docker --version

Example output:

Docker version 28.x.x

Once you see the Docker version, then verify Docker is running in your system with the command below:

docker ps

If no error appears, Docker Desktop is running and ready to use.

What is KRaft Mode?

KRaft (Kafka Raft Metadata Mode) is the modern architecture for Kafka.

Traditional Kafka Architecture

Kafka Broker
     +
 ZooKeeper

Modern Kafka Architecture

Kafka Broker
     +
 KRaft Controller

Benefits of KRaft Mode:

  • No ZooKeeper required
  • Simpler setup
  • Easier maintenance
  • Better scalability
  • Recommended for new Kafka deployments

The Confluent Local image automatically runs Kafka in KRaft mode.

Step 1: Run Confluent Kafka

Open Command Prompt, PowerShell, or Terminal and execute:

docker run -d --name kafka -p 9092:9092 confluentinc/confluent-local:latest

What This Command Does

OptionDescription
-dRuns the container in background mode
--name kafkaAssigns the container name “kafka”
-p 9092:9092Exposes Kafka broker port 9092
confluentinc/confluent-local:latestDownloads and runs the latest Confluent Local Kafka image

Important Note: If the image is not already available on your machine, Docker automatically downloads it before starting the container.

Step 2: Verify Kafka Container is Running

Run:

docker ps

Expected output:

CONTAINER ID   IMAGE                               STATUS
xxxxxxxxxxxx   confluentinc/confluent-local        Up

If the container status is Up, Kafka has started successfully.

Step 3: Check Kafka Logs

View container logs:

docker logs kafka

Look for messages similar to:

Kafka Server started
Transitioning from STARTING to STARTED

These messages indicate that Kafka is running correctly.

Step 4: Access the Kafka Container

Open a shell inside the Kafka container:

docker exec -it kafka bash

You are now inside the Kafka environment.

Step 5: Create a Kafka Topic

Create a topic named orders:

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

Expected output:

Created topic orders.

Step 6: Verify Topic Creation

List all available topics:

kafka-topics \
--list \
--bootstrap-server localhost:9092

Expected output:

orders

This confirms that Kafka is functioning properly.

Step 7: View Topic Details

Describe the topic:

kafka-topics \
--describe \
--topic orders \
--bootstrap-server localhost:9092

Example output:

Topic: orders
PartitionCount: 3
ReplicationFactor: 1

Step 8: Produce Messages

Start a producer:

kafka-console-producer \
--topic orders \
--bootstrap-server localhost:9092

Enter some messages:

Order Created 1001
Order Created 1002
Order Created 1003

Press Enter after each message.

Step 9: Consume Messages

Open another terminal window and enter the Kafka container:

docker exec -it kafka bash

Run the consumer:

kafka-console-consumer \
--topic orders \
--bootstrap-server localhost:9092 \
--from-beginning

Expected output:

Order Created 1001
Order Created 1002
Order Created 1003

This confirms that Kafka producers and consumers are working successfully.

How to Verify Kafka Installation

Use the following checklist.

Verify Container Status

docker ps

Expected:

STATUS = Up

Verify Kafka Logs

docker logs kafka

Expected:

Kafka Server started

Verify Topic Creation

kafka-topics --list --bootstrap-server localhost:9092

Expected:

orders

Verify Producer

kafka-console-producer

Able to send messages successfully.

Verify Consumer

kafka-console-consumer

Able to receive messages successfully.

If all these checks pass, Kafka is installed and running correctly.

Useful Docker Commands

Stop Kafka

docker stop kafka

Start Kafka

docker start kafka

Restart Kafka

docker restart kafka

View Logs Continuously

docker logs -f kafka

Remove Kafka Container

docker rm -f kafka

View Downloaded Images

docker images

Connect Spring Boot Application to Kafka

Configure Kafka in your Spring Boot application:

spring.kafka.bootstrap-servers=localhost:9092

That’s all you need to connect your producer and consumer applications to Kafka running inside Docker Desktop.

Common Issues and Solutions

Kafka Container Not Running

Check:

docker ps -a

View logs:

docker logs kafka

Port 9092 Already in Use

Check which application is using the port:

Windows:

netstat -ano | findstr 9092

Linux/macOS:

netstat -an | grep 9092

Stop the conflicting application and restart Kafka.

Spring Boot Cannot Connect to Kafka

Verify:

spring.kafka.bootstrap-servers=localhost:9092

Also, verify the Kafka container is running:

docker ps

Conclusion

Installing Confluent Kafka using Docker Desktop has become incredibly simple with the Confluent Local image. With a single Docker command, you can start a fully functional Kafka broker running in KRaft mode without configuring ZooKeeper or managing complex Kafka settings.

In this tutorial, you learned how to:

  • Install Confluent Kafka using Docker Desktop
  • Run Kafka in KRaft mode
  • Create and manage Kafka topics
  • Produce and consume messages
  • Verify a successful Kafka installation
  • Connect Spring Boot applications to Kafka

You now have a local Kafka environment ready for building real-world Spring Boot microservices, event-driven applications, and streaming solutions.

Share with friends

Leave a Comment

Your email address will not be published. Required fields are marked *