docker-compose.yml
version: '3.8'
services:
zoo1:
image: zookeeper
hostname: zoo1
ports:
- 2181:2181
volumes:
- zoo1:/data
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper
hostname: zoo2
ports:
- 2182:2181
volumes:
- zoo2:/data
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper
hostname: zoo3
ports:
- 2183:2181
volumes:
- zoo3:/data
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
volumes:
zoo1:
driver_opts:
type: "nfs"
o: "addr=192.168.140.130,rw"
device: ":/srv/nfs/zoo1"
zoo2:
driver_opts:
type: "nfs"
o: "addr=192.168.140.130,rw"
device: ":/srv/nfs/zoo2"
zoo3:
driver_opts:
type: "nfs"
o: "addr=192.168.140.130,rw"
device: ":/srv/nfs/zoo3"
docker stack deploy -c docker-compose.yml zoo
docker service ls
注意事项:
- docker-compose.yml 更新后建议换一个 stack 名重启
- nfs 目录的权限
- nfs 服务的集群高可用