Created
August 15, 2025 13:09
-
-
Save thuykaka/e230f9794eebcc8cadaede581917585b to your computer and use it in GitHub Desktop.
Docker compose for kafka kraft
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
| services: | |
| kafka: | |
| image: apache/kafka:3.9.1 | |
| container_name: kafka | |
| restart: unless-stopped | |
| ports: | |
| - "9092:9092" | |
| environment: | |
| KAFKA_NODE_ID: 1 | |
| KAFKA_PROCESS_ROLES: broker,controller | |
| KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 | |
| KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.13:9092 | |
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT | |
| KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER | |
| KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093 | |
| KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | |
| KAFKA_NUM_PARTITIONS: 1 | |
| KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | |
| KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | |
| KAFKA_SHARE_COORDINATOR_STATE_TOPIC_REPLICATION_FACTOR: 1 | |
| KAFKA_SHARE_COORDINATOR_STATE_TOPIC_MIN_ISR: 1 | |
| KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | |
| KAFKA_CFG_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | |
| KAFKA_LOG_RETENTION_HOURS: 24 | |
| healthcheck: | |
| test: ['CMD', '/opt/kafka/bin/kafka-broker-api-versions.sh', '--bootstrap-server', 'kafka:9092'] | |
| interval: 10s | |
| timeout: 10s | |
| retries: 5 | |
| start_period: 30s | |
| volumes: | |
| - kafka_data:/var/lib/kafka/data | |
| networks: | |
| - kafka-net | |
| kafka-ui: | |
| image: provectuslabs/kafka-ui:latest | |
| container_name: kafka-ui | |
| restart: unless-stopped | |
| ports: | |
| - "8088:8080" | |
| environment: | |
| KAFKA_CLUSTERS_0_NAME: local | |
| KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092 | |
| KAFKA_CLUSTERS_0_READONLY: "false" | |
| depends_on: | |
| kafka: | |
| condition: service_healthy | |
| networks: | |
| - kafka-net | |
| volumes: | |
| kafka_data: | |
| networks: | |
| kafka-net: | |
| driver: bridge |
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
| #!/bin/bash | |
| # Kafka Docker Compose Runner | |
| # Automatically stops existing containers and starts fresh | |
| echo "๐ Starting Kafka Docker Compose..." | |
| # Check if containers are running and stop them | |
| echo "๐ Checking for existing containers..." | |
| # Stop and remove containers if they exist | |
| if [ "$(docker ps -q -f name=kafka)" ]; then | |
| echo "โน๏ธ Stopping existing Kafka container..." | |
| docker stop kafka | |
| fi | |
| if [ "$(docker ps -q -f name=kafka-ui)" ]; then | |
| echo "โน๏ธ Stopping existing Kafka UI container..." | |
| docker stop kafka-ui | |
| fi | |
| # Remove containers if they exist | |
| if [ "$(docker ps -aq -f name=kafka)" ]; then | |
| echo "๐๏ธ Removing existing Kafka container..." | |
| docker rm kafka | |
| fi | |
| if [ "$(docker ps -aq -f name=kafka-ui)" ]; then | |
| echo "๐๏ธ Removing existing Kafka UI container..." | |
| docker rm kafka-ui | |
| fi | |
| # Start fresh containers | |
| echo "๐ Starting fresh containers..." | |
| docker-compose up -d --force-recreate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment