一、在官網拉取鏡像docker
docker pull zookeeper
二、根據鏡像啓動zookeeper容器spa
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
三、啓動zookeeper集羣命令行命令行
docker run -it --rm --link zookeeper1:zookeeper1 --link zookeeper2:zookeeper2 --link zookeeper3:zookeeper3 zookeeper zkCli.sh -server zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
而後就可使用了。code