day06-20200720
p24.dockerfile案例编写-1
 
1.创建好容器时,进去容器的时候,修改所在的当前目录。
2.新添加命令。支持vim、ifconfig
备注:原来的镜像容器默认是不满足上面的条件的。
第一步:DockerFile编写
 
DockerFile_20200720_1
FROM centos
 
MAINTAINER fengyarong
 
ENV mypath /tmp
 
WORKDIR $mypath
 
RUN yum -y install vim
RUN yum -y install net-tools
 
EXPOSE 80
 
CMD echo $mypath
CMD echo "success -----ok"
CMD /bin/bash
 
第二步:构建镜像
【docker build -f /tmp/mydockerfile/DockerFile_20200720_1 -t fyr/centos:20200720.1 .】
【.】表示当前目录
 
第三步:运行容器
【docker run -it fyr/centos:20200720.1】
 
附加:【docker history 镜像id】可以查看本次镜像的构建过程。
 
p25.dockerfile案例编写-2
 
【CMD】和【ENTRYPOINT】如何区别?
 
通过镜像部署tomcat之所以运行就启动是因为,文件dockerfile里面最后有一句【CMD ["catalina.sh","run"]】
 
假设我们现在【docker run -it -p 8888:8080 tomcat ls -l】tomcat还会自动运行吗?
不会,容器启动后运行了ls -l就停止了。tomcat的目录。
 
第一步:编写dockerfile
DockerFile_20200720_2
FROM centos
RUN yum -y install curl
CMD [ "curl","-s","http://ip.cn" ]
 
第二步:构建镜像
【docker build -f DockerFile_20200720_2 -t fyr/centos:20200720.2 .】
 
第三步:运行容器
【docker run -it fyr/centos:20200720.2】
显示ip
【docker run -it fyr/centos:20200720.2 -i】
会报错,找不到-i这个命令
所以是不可以直接运行的,而是覆盖CMD [ "curl","-s","http://ip.cn" ]命令。
 
第四步:重新编写dockersfile
DockerFile_20200720_3
FROM centos
RUN yum -y install curl
ENTRYPOINT [ "curl","-s","http://ip.cn" ]
 
第五步:构建镜像
【docker build -f DockerFile_20200720_3 -t fyr/centos:20200720.3 .】
 
第六步:运行容器
【docker run -it fyr/centos:20200720.3】
显示ip
【docker run -it fyr/centos:20200720.3 -i】
成功解析,并显示ip
证明命令都执行,而不是覆盖。