创建 network
1
docker network create --driver bridge --subnet 172.22.0.0/16 --gateway 172.22.0.1 op_net
创建 zookeeper.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
49version: '3.1'
services:
zk-1:
image: zookeeper
restart: always
hostname: zk-1
container_name: zk-1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zk-2:2888:3888 server.3=zk-3:2888:3888
networks:
default:
ipv4_address: 172.22.0.11
zk-2:
image: zookeeper
restart: always
hostname: zk-2
container_name: zk-2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zk-1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zk-3:2888:3888;
networks:
default:
ipv4_address: 172.22.0.12
zk-3:
image: zookeeper
restart: always
hostname: zk-3
container_name: zk-3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zk-1:2888:3888 server.2=zk-2:2888:3888 server.3=0.0.0.0:2888:3888
networks:
default:
ipv4_address: 172.22.0.13
networks:
default:
external:
name: op_net启动 ZooKeeper 集群
1
docker-compose -f zookeeper.yml up -d
参考资料: