Last active
November 3, 2025 16:39
-
-
Save erikkinding/975eb85a317ef8bfad9852225ece53f8 to your computer and use it in GitHub Desktop.
Docker compose for local Kafka setup with kafka-ui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This setup allows you to both connect from within the docker-compose context as well as from services running on your local | |
| # machine but not as part of the docker-compose setup. Any client connecting to the broker from the outside can connect to | |
| # localhost:9092 while services running as part of the docker-compose connect to broker:9093. | |
| # | |
| # To access kafka-ui: http://localhost:7777 | |
| # | |
| # I hope this helps someone out there! :) | |
| version: '3' | |
| networks: | |
| local-kafka: | |
| driver: bridge | |
| services: | |
| zookeeper: | |
| image: confluentinc/cp-zookeeper:7.0.1 | |
| container_name: zookeeper | |
| networks: | |
| - local-kafka | |
| environment: | |
| ZOOKEEPER_CLIENT_PORT: 2181 | |
| ZOOKEEPER_TICK_TIME: 2000 | |
| broker: | |
| image: confluentinc/cp-kafka:7.0.1 | |
| container_name: broker | |
| networks: | |
| - local-kafka | |
| ports: | |
| # To learn about configuring Kafka for access across networks see | |
| # https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/ | |
| - "9092:9092" | |
| - "9093:9093" | |
| depends_on: | |
| - zookeeper | |
| environment: | |
| KAFKA_BROKER_ID: 1 | |
| KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' | |
| KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | |
| KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | |
| KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | |
| KAFKA_LISTENERS: PLAINTEXT_INTERNAL://0.0.0.0:29092,PLAINTEXT_C://0.0.0.0:9093,PLAINTEXT_L://0.0.0.0:9092, | |
| KAFKA_ADVERTISED_LISTENERS: PLAINTEXT_INTERNAL://broker:29092,PLAINTEXT_L://localhost:9092,PLAINTEXT_C://broker:9093 | |
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT_INTERNAL:PLAINTEXT,PLAINTEXT_L:PLAINTEXT,PLAINTEXT_C:PLAINTEXT | |
| KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_INTERNAL | |
| kafka-ui: | |
| image: provectuslabs/kafka-ui | |
| container_name: kafka-ui | |
| networks: | |
| - local-kafka | |
| depends_on: | |
| - broker | |
| ports: | |
| - "7777:8080" | |
| restart: always | |
| environment: | |
| - KAFKA_CLUSTERS_0_NAME=broker | |
| - KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=broker:9093 | |
| - KAFKA_CLUSTERS_0_ZOOKEEPER=zookeeper:2181 |
Tks!
❤️
If you want to use latest version kafka, ie kafka 4.0.0, use the below docker-compose.yaml content.
System requirement is also less compared to the one given at top.
broker:
image: apache/kafka:latest
hostname: broker
container_name: broker
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_NODE_ID: 1
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@broker:29093
KAFKA_LISTENERS: PLAINTEXT://broker:29092,CONTROLLER://broker:29093,PLAINTEXT_HOST://0.0.0.0:9092
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing.