Kafka 4.3.1 with KRaft, Java 21, persistence, JMX, and configurable topics.
49
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.
kafka userKAFKA_EXTRA_CONFIG9999docker 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
| Variable | Description |
|---|---|
KAFKA_CFG_PROCESS_ROLES | Kafka process roles, e.g. broker,controller |
KAFKA_CFG_NODE_ID | Unique Kafka node ID |
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS | KRaft controller quorum configuration |
KAFKA_CFG_LISTENERS | Kafka listener configuration |
KAFKA_CFG_ADVERTISED_LISTENERS | Addresses advertised to clients |
| Variable | Default | Description |
|---|---|---|
KAFKA_DATA_DIR | /var/lib/kafka/data | Kafka data directory |
KAFKA_CLUSTER_ID | Auto-generated | KRaft cluster ID |
KAFKA_CREATE_TOPICS | — | Comma-separated topics to create |
KAFKA_CREATE_TOPIC_PARTITIONS | 3 | Number of partitions for created topics |
KAFKA_CREATE_TOPIC_REPLICATION_FACTOR | 1 | Replication factor for created topics |
KAFKA_EXTRA_CONFIG | — | Additional Kafka configuration |
KAFKA_HEALTHCHECK_BOOTSTRAP | localhost:9092 | Bootstrap server used by the health check |
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
-e KAFKA_CREATE_TOPICS=events,orders \
-e KAFKA_CREATE_TOPIC_PARTITIONS=5 \
-e KAFKA_CREATE_TOPIC_REPLICATION_FACTOR=1
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.
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
| Port | Purpose |
|---|---|
9092 | Kafka broker |
9093 | KRaft controller |
9999 | JMX monitoring |
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 is enabled on port 9999 for monitoring and observability.
The JMX endpoint is configured without authentication or SSL.
Security: Do not expose port
9999to untrusted networks.
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.
You can execute Kafka CLI commands inside the container.
docker exec kafka \
bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--list
docker exec kafka \
bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--describe \
--topic events
docker exec -it kafka \
bin/kafka-console-producer.sh \
--bootstrap-server localhost:9092 \
--topic events
docker exec -it kafka \
bin/kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic events \
--from-beginning
Pull the image from Docker Hub:
docker pull catbee/kafka:4.3.1
Run the image:
docker run catbee/kafka:4.3.1
| Property | Value |
|---|---|
| Kafka | 4.3.1 |
| Java | 21 |
| Mode | KRaft |
| User | kafka |
| Data directory | /var/lib/kafka/data |
| Broker port | 9092 |
| Controller port | 9093 |
| JMX port | 9999 |
Kafka is distributed under the Apache License 2.0.
For Kafka licensing information, see the Apache Kafka project documentation.
Content type
Image
Digest
sha256:c45e6ccb3…
Size
224.1 MB
Last updated
2 days ago
docker pull catbee/kafka:4.3.1