将俩个文件放在同一目录下,执行
docker-compose up -d 即可
.env
ZK_MASTER_DIR=./master
ZK_SLAVE1_DIR=./slave1
ZK_SLAVE2_DIR=./slave2
docker-compose.yml:
version: "3.3"
services:
zk1:
image: zookeeper:3.4
restart: always
container_name: zk1
ports:
- "2181:2181"
volumes:
- ${ZK_MASTER_DIR}/data:/data
- ${ZK_MASTER_DIR}/datalog:/datalog
- ${ZK_MASTER_DIR}/conf:/conf
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:2888:3888 server.3=zk3:2888:3888
# networks:
# zk-master:
# ipv4_address: 172.50.0.10
zk2:
image: zookeeper:3.4
restart: always
container_name: zk2
ports:
- "2182:2181"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:2888:3888 server.3=zk3:2888:3888
volumes:
- ${ZK_SLAVE1_DIR}/data:/data
- ${ZK_SLAVE1_DIR}/datalog:/datalog
- ${ZK_SLAVE1_DIR}/conf:/conf
# networks:
# zk-slave:
# ipv4_address: 172.30.0.2
zk3:
image: zookeeper:3.4
restart: always
container_name: zk3
ports:
- "2183:2181"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:2888:3888 server.3=zk3:2888:3888
volumes:
- ${ZK_SLAVE2_DIR}/data:/data
- ${ZK_SLAVE2_DIR}/datalog:/datalog
- ${ZK_SLAVE2_DIR}/conf:/conf
# networks:
# zk-slave:
# ipv4_address: 172.30.0.3
networks:
zk-master:
driver: bridge # 创建一个docker 的桥接网络
ipam:
driver: default
config:
-
subnet: 172.50.0.0/16
zk-slave:
driver: bridge
ipam:
driver: default
config:
-
subnet: 172.30.0.0/16