Install docker and set up the environment
yum install -y docker
systemctl enable docker
service docker start
A management interface for docker
docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock uifd/ui-for-docker
Set up Dockerfile
# Build from a base image centos:6.8 FROM centos:6.8 # maintainer info MAINTAINER xiaofancn "[email protected]" #Container environment processing RUN mkdir /usr/local/jdk #Add the jdk folder in the current directory to the mirror ADD jdk1.8.0_161 /usr/local/jdk/jdk1.8.0_161 ADD zookeeper-3.4.11 /root/zookeeper-3.4.11 ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_161 ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV PATH $JAVA_HOME/bin:$PATH RUN java -version VOLUME ["/data1"] #The command to execute when starting the container #Container entry, turn the zookeeper container into a zookeeper server #docker run -p 2181:2181 --name docker-zookeeper xiaofancn/zookeeper print-cmd ENTRYPOINT ["/root/zookeeper-3.4.11/bin/zkServer.sh"] #Running in the foreground, if this is not set, if zookeeper runs in the background, the container will automatically close and enter the Exited state #Parameters followed when the container starts = docker run -p 2181:2181 --name docker-zookeeper xiaofancn/zookeeper start-foreground #Append parameters such as print-cmd when starting, which will override the default parameters #start-foreground output logs, the output of logs is kept in the container, and the docker keeps the up state. CMD ["start-foreground"] #exposed ports EXPOSE 2181 2888 3888
build image
docker build -t="xiaofancn/zookeeper" .
Clean up before startup
docker stop docker-zookeeper && docker rm docker-zookeeper
docker run -d -p 2181:2181 --name docker-zookeeper xiaofancn/zookeeper
docker inspect docker-zookeeper
zk for linked container
./zookeeper-3.4.11//bin/zkCli.sh -server localhost:2181
Create a new set of subnets
docker network create --subnet=172.18.0.0/16 shadownet
Bind ip to start zk
docker run --network=shadownet --ip=172.18.0.10 -d -p 2181:2181 --name docker-zookeeper_1 xiaofancn/zookeeper
docker run --network=shadownet --ip=172.18.0.11 -d -p 2182:2181 --name docker-zookeeper_2 xiaofancn/zookeeper
开两个控制台分别执行
docker run -it --network=shadownet --ip=172.18.0.12 centos:6.8 /bin/bash
docker run -it --network=shadownet --ip=172.18.0.13 centos:6.8 /bin/bash
修改镜像(由于centos没有ping工具包,在基础包上安装后,提交成一个版本)
docker run -it --network=shadownet --ip=172.18.0.12 centos:6.8 /bin/bash
[root@e2bdf95d0658 /]# yum install iputils -y && exit
修改的镜像历史为 e2bdf95d0658 并提交成centos:6.8.v1 版本
docker commit -m "Added ping " -a "Docker Centosping" e2bdf95d0658 centos:6.8.v1
从提交版再进入
docker run -it --network=shadownet --ip=172.18.0.12 centos:6.8.v1 /bin/bash
[root@56ddbd3270b2 /]# ping www.baidu.com
PING www.a.shifen.com (119.75.216.20) 56(84) bytes of data.
64 bytes from 119.75.216.20: icmp_seq=1 ttl=54 time=7.94 ms
参考
https://www.cnblogs.com/zhouyalei/p/6400951.html