Skip to content

Instantly share code, notes, and snippets.

@cakiem8x
Forked from everpeace/docker-compose.yml
Created June 14, 2021 04:30
Show Gist options
  • Save cakiem8x/c2a4bde8d37ef1cdbaaead15d9061fe6 to your computer and use it in GitHub Desktop.
Save cakiem8x/c2a4bde8d37ef1cdbaaead15d9061fe6 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