1、登陆docker hut官方网站:https://hub.docker.com/
2、search centos
3、docker pull centos:7.2.1511
4、创建Dockerfile文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@vmhost centos7.2] # cat Dockerfile
[plain] view plain copy
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文件在当前路径时用. 标示就可以,如果不在使用绝对路径
1
|
docker build -t 4paradigm/centos:7.2 .
|
6、启动容器脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@vmhost prophet2.0] # cat prophet-3.sh
[plain] view plain copy
#!/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
|
以上所述是小编给大家介绍的docker官方镜像下载及使用Dockerfile创建镜像的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://blog.csdn.net/szh1124/article/details/54970727