One download zookeeper package
http://apache.osuosl.org/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
2. Make a Docker image of zookeeper
1 Use ubuntu16.04 basic image, and install jdk1.8 on this image
2 Press the zookeeper-3.4.9.tar.gz and transfer it into the basic image by file mounting, configure $ ZOOKEEPER_HOME , but put $ ZOOKEEPER_HOME /zookeeper-3.4.9/conf , then commit the image and name it zookeeper :1.0
3 Make a regular zookeeper image based on zookeeper: 1.0 zookeeper: 2.0
Dockerfile:
FROM zookeeper:1.0 MAINTAINER dean ENV JAVA_HOME /usr/local/java/ ENV ZOOKEEPER_HOME /opt/tools/zookeeper/zookeeper-3.4.9 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib ENV PATH $PATH:$JAVA_HOME/bin
4 Start the docker cluster
docker run -d -i -t -p 2181:2181 -p 2887:2887 -p 3887:3887 -v /usr/local/zookeeper/zookeeperServer1:/opt/tools/zookeeper/zookeeper-3.4.9/conf -v /usr/local/zookeeper/zookeeperServer1/data:/usr/local/zookeeperLog zookeeper:2.0 /bin/bash
docker run -d -i -t -p 2182:2182 -p 2888:2888 -p 3888:3888 -v /usr/local/zookeeper/zookeeperServer2:/opt/tools/zookeeper/zookeeper-3.4.9/conf -v /usr/local/zookeeper/zookeeperServer2/data:/usr/local/zookeeperLog/ zookeeper:2.0 /bin/bash
docker run -d -i -t -p 2183:2183 -p 2889:2889 -p 3889:3889 -v /usr/local/zookeeper/zookeeperServer3:/opt/tools/zookeeper/zookeeper-3.4.9/conf -v /usr/local/zookeeper/zookeeperServer3/data:/usr/local/zookeeperLog zookeeper:2.0 /bin/bash
It is worth noting that the zookeeper configuration file
server1
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit = 10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeperLog/
dataLogDir=/usr/local/zookeeperLog/
# the port at which the clients will connect
clientPort=2181
server.1=0.0.0.0:2887:3887
server.2=10.108.68.140:2888:3888
server.3=10.108.68.140:2889:3889
server2
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit = 10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeperLog/
dataLogDir=/usr/local/zookeeperLog/
# the port at which the clients will connect
clientPort=2182
server.1=10.108.68.140:2887:3887
server.2=0.0.0.0:2888:3888
server.3=10.108.68.140:2889:3889
server3
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit = 10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeperLog/
dataLogDir=/usr/local/zookeeperLog/
# the port at which the clients will connect
clientPort=2183
server.1=10.108.68.140:2887:3887
server.2=10.108.68.140:2888:3888
server.3=0.0.0.0:2889:3889
Finally, check the operation of the cluster through zkCli.sh -server 10.108.68.140:2181