Sign inSign up

catbee/kafka

By catbee

•Updated 2 days ago

Kafka 4.3.1 with KRaft, Java 21, persistence, JMX, and configurable topics.

Image
Message queues
0

49

catbee/kafka repository overview

⁠Kafka 4.3.1 Docker Image

A lightweight Apache Kafka 4.3.1 Docker image running in KRaft mode with Java 21, persistent storage, configurable topics, health checks, and JMX monitoring.

⁠Features

  • Apache Kafka 4.3.1
  • Java 21
  • KRaft mode — no ZooKeeper required
  • Runs as a non-root kafka user
  • Persistent Kafka data volume
  • Configurable listeners and advertised listeners
  • Optional topic creation on startup
  • Custom Kafka configuration through KAFKA_EXTRA_CONFIG
  • JMX enabled on port 9999
  • Docker health check
  • Graceful shutdown handling

⁠Quick Start

docker run -d \
  --name kafka \
  -p 9092:9092 \
  -p 9093:9093 \
  -p 9999:9999 \
  -e KAFKA_CFG_PROCESS_ROLES=broker,controller \
  -e KAFKA_CFG_NODE_ID=1 \
  -e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@localhost:9093 \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 \
  -e KAFKA_CREATE_TOPICS=events,orders,users \
  -v kafka-data:/var/lib/kafka/data \
  catbee/kafka:4.3.1

⁠Configuration

⁠Required Environment Variables
VariableDescription
KAFKA_CFG_PROCESS_ROLESKafka process roles, e.g. broker,controller
KAFKA_CFG_NODE_IDUnique Kafka node ID
KAFKA_CFG_CONTROLLER_QUORUM_VOTERSKRaft controller quorum configuration
KAFKA_CFG_LISTENERSKafka listener configuration
KAFKA_CFG_ADVERTISED_LISTENERSAddresses advertised to clients
⁠Optional Environment Variables
VariableDefaultDescription
KAFKA_DATA_DIR/var/lib/kafka/dataKafka data directory
KAFKA_CLUSTER_IDAuto-generatedKRaft cluster ID
KAFKA_CREATE_TOPICS—Comma-separated topics to create
KAFKA_CREATE_TOPIC_PARTITIONS3Number of partitions for created topics
KAFKA_CREATE_TOPIC_REPLICATION_FACTOR1Replication factor for created topics
KAFKA_EXTRA_CONFIG—Additional Kafka configuration
KAFKA_HEALTHCHECK_BOOTSTRAPlocalhost:9092Bootstrap server used by the health check

⁠Creating Topics

Topics can be created automatically when the container starts:

docker run -d \
  --name kafka \
  -p 9092:9092 \
  -p 9093:9093 \
  -e KAFKA_CFG_PROCESS_ROLES=broker,controller \
  -e KAFKA_CFG_NODE_ID=1 \
  -e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@localhost:9093 \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 \
  -e KAFKA_CREATE_TOPICS=events,orders,users \
  -v kafka-data:/var/lib/kafka/data \
  catbee/kafka:4.3.1
⁠Configure Partitions and Replication
-e KAFKA_CREATE_TOPICS=events,orders \
-e KAFKA_CREATE_TOPIC_PARTITIONS=5 \
-e KAFKA_CREATE_TOPIC_REPLICATION_FACTOR=1

⁠Custom Kafka Configuration

Additional Kafka properties can be supplied through KAFKA_EXTRA_CONFIG.

For example, to disable automatic topic creation:

-e KAFKA_EXTRA_CONFIG="auto.create.topics.enable=false
num.partitions=3"

These properties are appended to the generated Kafka configuration.

⁠Persistent Storage

Kafka data is stored in:

/var/lib/kafka/data

Use a Docker volume to persist Kafka data across container restarts:

-v kafka-data:/var/lib/kafka/data

Example:

docker run -d \
  --name kafka \
  -p 9092:9092 \
  -p 9093:9093 \
  -v kafka-data:/var/lib/kafka/data \
  ...
  catbee/kafka:4.3.1

⁠Ports

PortPurpose
9092Kafka broker
9093KRaft controller
9999JMX monitoring

⁠Health Check

The image includes a Docker health check that verifies Kafka can accept metadata requests through the configured bootstrap server.

Check the container health with:

docker ps

Or:

docker inspect kafka \
  --format='{{.State.Health.Status}}'

A healthy container reports:

healthy

⁠JMX Monitoring

JMX is enabled on port 9999 for monitoring and observability.

The JMX endpoint is configured without authentication or SSL.

Security: Do not expose port 9999 to untrusted networks.

⁠Persistence and Restart

Kafka data is persisted in the configured Docker volume, allowing topics and messages to survive container restarts.

Restart the container:

docker restart kafka

The Kafka data remains available after the restart as long as the same Docker volume is used.

⁠Running Kafka CLI Commands

You can execute Kafka CLI commands inside the container.

⁠List Topics
docker exec kafka \
  bin/kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --list
⁠Describe a Topic
docker exec kafka \
  bin/kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --describe \
  --topic events
⁠Produce Messages
docker exec -it kafka \
  bin/kafka-console-producer.sh \
  --bootstrap-server localhost:9092 \
  --topic events
⁠Consume Messages
docker exec -it kafka \
  bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 \
  --topic events \
  --from-beginning

⁠Image

Pull the image from Docker Hub:

docker pull catbee/kafka:4.3.1

Run the image:

docker run catbee/kafka:4.3.1

⁠Image Details

PropertyValue
Kafka4.3.1
Java21
ModeKRaft
Userkafka
Data directory/var/lib/kafka/data
Broker port9092
Controller port9093
JMX port9999

⁠License

Kafka is distributed under the Apache License 2.0.

For Kafka licensing information, see the Apache Kafka project documentation.

Tag summary

Content type

Image

Digest

sha256:c45e6ccb3…

Size

224.1 MB

Last updated

2 days ago

docker pull catbee/kafka:4.3.1