1. 程式人生 > >docker官方映象下載及使用Dockerfile建立映象

docker官方映象下載及使用Dockerfile建立映象

2、search centos 3、docker pull centos:7.2.1511 4、建立Dockerfile檔案: [[email protected] centos7.2]# cat Dockerfile
FROM centos:7.2.1511
MAINTAINER wanghongwei([email protected])
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、啟動容器指令碼: [[email protected] 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/
[email protected]
$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/[email protected]$GATEWAY docker exec -d $HOST_NAME /usr/sbin/sshd -D else echo "docker start exception" fi