docker 镜像方式 zookeeper单机和集群部署

Zookeeper单机部署
1.拉取镜像
docker pull zookeeper:latest

2.启动zookeeper镜像
docker run --name zookeeper -p 2181:2181 --restart always -d zookeeper:latest

Zookeeper集群部署
1.docker-compose的安装
1.1下载docker-compose
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-uname -s-uname -m > /usr/local/bin/docker-compose

1.2将可执行权限应用于二进制文件
chmod +x /usr/local/bin/docker-compose

1.3测试是否安装成功
docker-compose --version

2.集群部署
2.1将 docker-compose.yml 保存到当前命令行目录下
version: ‘3.1’

services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

zoo2:
image: zookeeper
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

zoo3:
image: zookeeper
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
2.2启动集群
docker-compose up -d
2.3 检查是否启动成功
docker ps
docker-compose ps

2.4查看是主机还是从机
docker exec -it zookeeper_zoo3_1 bash ./bin/zkServer.sh status

你可能感兴趣的:(docker,zookeeper,容器)