使用docker 搭建
使用docker-compose 搭建zookeeper集群
-
下载 镜像
docker pull zookeeper
-
新建 docker-compose.yml 文件
version: '2'
services:
zoo1:
# 镜像名称
image: zookeeper
# 重启docker 自动重启容器
restart: always
# 定义容器名
container_name: zoo1
# 使用宿主 ip
net: host
# 对外开放端口映射
ports:
- "2181:2181"
# 挂载 容器地址到 宿主机
volumes:
- "D:/Program Files (x86)/dockerdata/zookeeper/0/data:/data"
- "D:/Program Files (x86)/dockerdata/zookeeper/0/datalog:/datalog"
# 环境变量
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo2:
image: zookeeper
restart: always
container_name: zoo2
net: host
ports:
- "2182:2181"
volumes:
- "D:/Program Files (x86)/dockerdata/zookeeper/1/data:/data"
- "D:/Program Files (x86)/dockerdata/zookeeper/1/datalog:/datalog"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo3:
image: zookeeper
restart: always
container_name: zoo3
net: host
ports:
- "2183:2181"
volumes:
- "D:/Program Files (x86)/dockerdata/zookeeper/2/data:/data"
- "D:/Program Files (x86)/dockerdata/zookeeper/2/datalog:/datalog"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
- 启动
- 进入docker-composeyml所在目录
- 执行命令docker-compose up
- 查看容器
- 进入docker-composeyml所在目录
- 执行docker-compose ps / docker ps
- 关闭容器
- 进入docker-composeyml所在目录
- 执行命令 docker-compose stop
- 删除容器
- 进入docker-composeyml所在目录
- 执行命令 docker-compose down
网友评论