1、setup.sh
setup.sh脚本用来创建本地文件夹,这些文件夹会被挂载到docker容器。
#!/bin/bashmkdir -p "$PWD\zoo1\data"
mkdir -p "$PWD\zoo1\datalog"mkdir -p "$PWD\zoo2\data"
mkdir -p "$PWD\zoo2\datalog"mkdir -p "$PWD\zoo3\data"
mkdir -p "$PWD\zoo3\datalog"
生成的文件夹
2、docker-compose.yml
version: '3.1'
services:zoo1:image: zookeeper:3.6.3restart: alwayscontainer_name: zoo1ports:- "2181:2181"environment:ZOO_MY_ID: 1ZOO_TICK_TIME: 20000ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./zoo1/data:/data- ./zoo1/datalog:/datalogzoo2:image: zookeeper:3.6.3restart: alwayscontainer_name: zoo2ports:- "2182:2181"environment:ZOO_MY_ID: 2ZOO_TICK_TIME: 20000ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./zoo2/data:/data- ./zoo2/datalog:/datalogzoo3:image: zookeeper:3.6.3restart: alwayscontainer_name: zoo3ports:- "2183:2181"environment:ZOO_MY_ID: 3ZOO_TICK_TIME: 20000ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181volumes:- ./zoo3/data:/data- ./zoo3/datalog:/datalog
3、启动
docker-compose up
4、测试
安装zookeeper客户端
docker run -it --rm \--link zoo1:zk1 \--link zoo2:zk2 \--link zoo3:zk3 \--net zookeeper_default \zookeeper:3.6.3 zkCli.sh -server zk1:2181,zk2:2181,zk3:2181
成功连接