dockerfile是用来构建docker镜像的文件,命令和参数组成的脚本。docker
以前用别人的镜像,之后本身也能够写镜像。vim
本身作一个镜像centos
# 查看当前路径 ➜ file pwd /Users/dada/Downloads/docker-centos/file ➜ file ls # 建立文件 ➜ file touch myDockerfie # 编辑文件 ➜ file vim myDockerfie # 查看编辑的内容 ➜ file cat myDockerfie FROM centos MAINTAINER smallForest<1032817724@qq.com> ENV MYPATH /usr/local WORKDIR $MYPATH RUN yum -y install vim RUN yum -y install net-tools EXPOSE 80 CMD echo $MYPATH CMD echo "----end----" CMD /bin/bash # 进行构建镜像,若是文件名字是Dockerfile,则能够不用-f 指定文件路径 ➜ file docker build -f myDockerfie -t mycentos03:1.0 . [+] Building 85.8s (8/8) FINISHED => [internal] load build definition from myDockerfie 0.0s => => transferring dockerfile: 255B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/centos:latest 0.0s => [1/4] FROM docker.io/library/centos 0.0s => CACHED [2/4] WORKDIR /usr/local 0.0s => [3/4] RUN yum -y install vim 73.6s => [4/4] RUN yum -y install net-tools 11.3s => exporting to image 0.7s => => exporting layers 0.7s => => writing image sha256:13fa3a8f9134f7b7b0e76e2b22ee68d07a09bc1e927365474a66fcc8a3666e6a 0.0s => => naming to docker.io/library/mycentos03:1.0 # 查看结果 ➜ file docker images|grep mycentos03 mycentos03 1.0 13fa3a8f9134 59 seconds ago 282MB ➜ file docker run -d -it --name mycentos03 mycentos03:1.0 bf6575057cbf0517eeb4ec70d98ef4e232c4246174e4dc15e4f2c1cbd4d917db ➜ file docker ps|grep mycentos03 bf6575057cbf mycentos03:1.0 "/bin/sh -c /bin/bash" 13 seconds ago Up 12 seconds 80/tcp mycentos03 ➜ file docker exec -it bf6575057cbf /bin/bash [root@bf6575057cbf local]# ls bin etc games include lib lib64 libexec sbin share src # 查看工做目录和设置的/usr/local是否一致 [root@bf6575057cbf local]# pwd /usr/local [root@bf6575057cbf local]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.6 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:06 txqueuelen 0 (Ethernet) RX packets 9 bytes 726 (726.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@bf6575057cbf local]# vim a.sh [root@bf6575057cbf local]# # 运行结果发现,vim ifconfig是能够使用的,由于yum install进行了安装
docker history 镜像ID,能够查看镜像的构建历史数组
➜ file docker history 13fa3a8f9134 IMAGE CREATED CREATED BY SIZE COMMENT 13fa3a8f9134 8 minutes ago CMD ["/bin/sh" "-c" "/bin/bash"] 0B buildkit.dockerfile.v0 <missing> 8 minutes ago CMD ["/bin/sh" "-c" "echo \"----end----\""] 0B buildkit.dockerfile.v0 <missing> 8 minutes ago CMD ["/bin/sh" "-c" "echo $MYPATH"] 0B buildkit.dockerfile.v0 <missing> 8 minutes ago EXPOSE map[80/tcp:{}] 0B buildkit.dockerfile.v0 <missing> 8 minutes ago RUN /bin/sh -c yum -y install net-tools # bu… 14.4MB buildkit.dockerfile.v0 <missing> 8 minutes ago RUN /bin/sh -c yum -y install vim # buildkit 58.1MB buildkit.dockerfile.v0 <missing> 39 hours ago WORKDIR /usr/local 0B buildkit.dockerfile.v0 <missing> 39 hours ago ENV MYPATH=/usr/local 0B buildkit.dockerfile.v0 <missing> 39 hours ago MAINTAINER smallForest<1032817724@qq.com> 0B buildkit.dockerfile.v0 <missing> 5 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 5 months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B <missing> 5 months ago /bin/sh -c #(nop) ADD file:bd7a2aed6ede423b7… 209MB