-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocker-compose.yml
84 lines (78 loc) · 3.44 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
version: '3.8'
networks:
kafka_network:
name: kafka_network
services:
zookeeper_server:
image: confluentinc/cp-zookeeper:7.0.1
container_name: zookeeper_server
hostname: zookeeper_server
networks:
- kafka_network
restart: always
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ports:
- "2181:2181"
healthcheck:
test: "echo stat | nc localhost $$ZOOKEEPER_CLIENT_PORT"
interval: 30s
timeout: 10s
retries: 10
kafka_server:
image: confluentinc/cp-kafka:7.0.1
container_name: kafka_server
hostname: kafka_server
networks:
- kafka_network
restart: always
depends_on:
- zookeeper_server
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper_server:2181
# Ref: https://www.youtube.com/watch?v=L--VuzFiYrM
# INTERNAL -- Kafka-Broker & Kafka-Client both running in Docker within the same Docker network, in just different containers
# > docker run -it --rm --name kafka_client_producer --network kafka_network confluentinc/cp-kafka:7.0.1 /bin/kafka-console-producer --bootstrap-server kafka_server:29092 --topic test_topic
# > docker run -it --rm --name kafka_client_consumer --network kafka_network confluentinc/cp-kafka:7.0.1 /bin/kafka-console-consumer --bootstrap-server kafka_server:29092 --topic test_topic
# EXTERNAL_SAME_HOST -- Kafka-Broker running in Docker and Kafka-Client on local machine
# > kafka-console-producer --bootstrap-server localhost:9092 --topic test_topic_2
# > kafka-console-consumer --bootstrap-server localhost:9092 --topic test_topic_2
# EXTERNAL_DIFFERENT_HOST -- Kafka-Broker running on external server ex. cloud and 157.245.80.232 is it's IP Address (better use DNS Names instead of IP)
# > kafka-console-producer --bootstrap-server 157.245.80.232:29093 --topic test_topic_3
# > kafka-console-consumer --bootstrap-server 157.245.80.232:29093 --topic test_topic_3
KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:9092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:29092
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka_server:29092,EXTERNAL_SAME_HOST://localhost:9092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_SCHEMA_REGISTRY_URL: "schema_registry:8081"
ports:
- "9092:9092"
- "29093:29093"
healthcheck:
# test: [ "CMD", "nc", "-z", "localhost", "9092" ]
test: ["CMD", "kafka-topics", "--bootstrap-server", "kafka_server:9092", "--list"]
interval: 30s
timeout: 10s
retries: 10
schema_registry:
image: confluentinc/cp-schema-registry:7.3.1
container_name: schema_registry
hostname: schema_registry
networks:
- kafka_network
restart: always
depends_on:
- zookeeper_server
environment:
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: "PLAINTEXT://kafka_server:29092"
SCHEMA_REGISTRY_HOST_NAME: schema_registry
SCHEMA_REGISTRY_LISTENERS: "http://0.0.0.0:8081"
ports:
- "8081:8081"
healthcheck:
test: ["CMD", "curl", "--output", "/dev/null", "--silent", "--head", "--fail", "http://schema_registry:8081/subjects"]
interval: 30s
timeout: 10s
retries: 10