version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka1:
image: confluentinc/cp-kafka:latest
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
kafka2:
image: confluentinc/cp-kafka:latest
ports:
- "9093:9092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
kafka3:
image: confluentinc/cp-kafka:latest
ports:
- "9094:9092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
docker-compose up -d 명령을 통해 컨테이너를 실행한다.
$ docker-compose up -d
[+] Running 5/5
- Network docker_default Created 0.7s
- Container docker-kafka3-1 Started 2.4s
- Container docker-kafka2-1 Started 3.2s
- Container docker-zookeeper-1 Started 3.6s
- Container docker-kafka1-1 Started
$ $ docker-compose exec kafka1 kafka-topics --create --topic my-topic --bootstrap-server kafka1:9092 --replication-factor 3 --partitions 3
Created topic my-topic.
$ docker-compose exec kafka1 kafka-topics --describe --topic my-topic --bootstrap-server kafka1:9092
Topic: my-topic TopicId: tCgMk5P3TS2Flgmlznb7aA PartitionCount: 3 ReplicationFactor: 3 Configs:
Topic: my-topic Partition: 0 Leader: 3 Replicas: 3,2,1 Isr: 3,2,1
Topic: my-topic Partition: 1 Leader: 1 Replicas: 1,3,2 Isr: 1,3,2
Topic: my-topic Partition: 2 Leader: 2 Replicas: 2,1,3 Isr: 2,1,3