1、登陆docker hut官方网站: https://hub.docker.com/
2、search centos
3、docker pull centos:7.2.1511
4、创建Dockerfile文件:
[root@vmhost centos7.2]# cat Dockerfile
FROM centos:7.2.1511
MAINTAINER wanghongwei(wanghongwei@4paradigm.com)
RUN yum install -y expect \
       && yum install -y openssh-clients openssh-server sudo rsync vim libaio strace wget telnet lsof lvm2 psmisc net-tools \
           && /usr/bin/ssh-keygen -A \
              && yum clean all 
RUN useradd work
RUN echo 123456 | passwd --stdin root
RUN echo work123 | passwd --stdin work
ADD jdk-8u121-linux-x64.tar.gz /home/work

#ENTRYPOINT ["/root/docker/images/centos7.2"]

5、创建docker镜像:Dockerfile文件在当前路径时用. 标示就可以,如果不在使用绝对路径
docker build -t 4paradigm/centos:7.2 .
6、启动容器脚本:
[root@vmhost prophet2.0]# cat prophet-3.sh
#!/bin/bash -xv

HOST_NAME=prophet-3
HOST_IP=172.27.4.5
GATEWAY=172.27.0.1
ISO_PATH=/root/iso
VOLUME_PATH=/home/whwstar/volume/prophet3
image=4paradigm/centos:7.2

if [ `docker ps -a | grep $HOST_NAME | wc -l` -eq 0 ];then
    mkdir -p $VOLUME_PATH
    docker run -itd -h $HOST_NAME --name=$HOST_NAME --net=none -v $ISO_PATH:$ISO_PATH -v  $VOLUME_PATH:/home/work $image /bin/bash
    pipework br0 $HOST_NAME $HOST_IP/20@$GATEWAY
    docker exec -d $HOST_NAME /usr/sbin/sshd -D
elif [ `docker ps -a | grep prophet-01 | wc -l` -eq 1 ];then
    docker start $HOST_NAME
    pipework br0 $HOST_NAME $HOST_IP/20@$GATEWAY
    docker exec -d $HOST_NAME /usr/sbin/sshd -D
else
    echo "docker start exception"
fi


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐