Skip to content

Instantly share code, notes, and snippets.

@everpeace
Last active April 7, 2024 10:00
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save everpeace/7a317860cab6c7fb39d5b0c13ec2543e to your computer and use it in GitHub Desktop.
Save everpeace/7a317860cab6c7fb39d5b0c13ec2543e to your computer and use it in GitHub Desktop.
kafka cluster in docker-compose.
# WARNING: This docker-compose.yml is only for testing purpose.
# Parameters:
# - name: CONFLUENT_PLATFORM_VERSION
# default: 3.0.0
# reference: https://hub.docker.com/u/confluentinc/
# Ports:
# - description: Major ports are exposed to host computer
# - zookeeper: 2181
# kafka1: 9091
# kafka2: 9092
# kafka3: 9093
# kafka4: 9094
# kafka5: 9095
# Tips:>
# - You can up part of the cluster with below command.
# $ docker-compose up -d kafka1 kafka2 kafka3
version: '3.3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
healthcheck:
test: echo stat | nc localhost 2181
interval: 10s
timeout: 10s
retries: 3
environment:
- ZOOKEEPER_SERVER_ID=1
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
- ZOOKEEPER_INIT_LIMIT=5
- ZOOKEEPER_SYNC_LIMIT=2
- ZOOKEEPER_SERVERS=zookeeper:2888:3888
kafka1:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9091:9091"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka1:9091
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9091
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=1
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka2:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka2:9092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=2
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka3:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9093:9093"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka3:9093
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=3
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka4:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9094:9094"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka4:9094
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=4
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka5:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-3.0.0}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9095:9095"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka5:9095
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9095
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=5
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment