DockerFile自定义简单的镜像
a.将centos的工作目录设置为/tmp/
b.安装vim编辑器
c.查看网络配置ifconfig支持
1.编写Dockerfile文件
#vim Dockerfile02
#基础镜像为centos:7
FROM centos:7
#设置工作目录
ENV MYPATH /tmp
WORKDIR $MYPATH
#安装vim,net-tools
RUN yum install -y vim
RUN yum install -y net-tools
#容器对外端口
EXPOSE 80
CMD echo $MYPATH
CMD /bin/bash
2.构建镜像 “docker build”
[root@aaa ~/mydocker]# docker build -f Dockerfile02 -t mycentos:01 .
Sending build context to Docker daemon 4.096 kB
Step 1/8 : FROM centos:7
---> b5b4d78bc90c
Step 2/8 : ENV MYPATH /tmp
---> Using cache
---> 319082c348c7
Step 3/8 : WORKDIR $MYPATH
---> Using cache
---> 942c27a53f8d
Step 4/8 : RUN yum -y install vim
---> Using cache
---> cde85780d424
Step 5/8 : RUN yum -y install net-tools
---> Using cache
---> 4b0217f59041
Step 6/8 : EXPOSE 80
---> Using cache
---> ba401ffa976c
Step 7/8 : CMD echo $MYPATH
---> Using cache
---> ddabd0922191
Step 8/8 : CMD /bin/bash
---> Using cache
---> dc7ce76bded4
Successfully built dc7ce76bded4
[root@aaa ~/mydocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos 01 dc7ce76bded4 4 minutes ago 432 MB
3.运行容器 “docker run”
[root@aaa ~/mydocker]# docker run -it --name test01 mycentos:01
4.查看镜像的历史
[root@aaa ~/mydocker/tomcat9]# docker history mycentos:01
IMAGE CREATED CREATED BY SIZE COMMENT
dc7ce76bded4 14 hours ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/b... 0 B
ddabd0922191 14 hours ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "ec... 0 B
ba401ffa976c 14 hours ago /bin/sh -c #(nop) EXPOSE 80/tcp 0 B
4b0217f59041 14 hours ago /bin/sh -c yum -y install net-tools 87 MB
cde85780d424 14 hours ago /bin/sh -c yum -y install vim 142 MB
942c27a53f8d 14 hours ago /bin/sh -c #(nop) WORKDIR /tmp 0 B
319082c348c7 14 hours ago /bin/sh -c #(nop) ENV MYPATH=/tmp 0 B
b5b4d78bc90c 3 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 3 months ago /bin/sh -c #(nop) LABEL org.label-schema.... 0 B
<missing> 3 months ago /bin/sh -c #(nop) ADD file:38e2d2a1a0cd869... 203 MB
作者:ccku
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有问题或建议,请多多赐教,非常感谢。