docker搭建zookeeper集群
1、在官网拉取镜像
docker pull zookeeper
2、根据镜像启动zookeeper容器
docker run -itd --name zookeeper1 -h zookeeper1 -e ZOO_MY_ID=1 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2181:2181 -p 2888:2888 -p 3888:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper docker run -itd --name zookeeper2 -h zookeeper2 -e ZOO_MY_ID=2 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2182:2181 -p 28881:2888 -p 38881:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper docker run -itd --name zookeeper3 -h zookeeper3 -e ZOO_MY_ID=3 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2183:2181 -p 28882:2888 -p 38882:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper
3、启动zookeeper集群命令行
docker run -it --rm --link zookeeper1:zookeeper1 --link zookeeper2:zookeeper2 --link zookeeper3:zookeeper3 zookeeper zkCli.sh -server zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
然后就可以使用了。