一、docker镜像的分层
1、图像呈现
2、命令呈现
[root@oldboy kod]# docker image history kod:v1 IMAGE CREATED CREATED BY SIZE COMMENT 25f70cb6dec6 42 minutes ago /bin/sh -c #(nop) CMD ["/bin/bash" "/init.s… 0B 2c08007784ad 42 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B beea547494c2 42 minutes ago /bin/sh -c #(nop) ADD file:9fded30cd1519b8d3… 70B 0accf7a7f519 42 minutes ago /bin/sh -c chmod -R 777 /var/www/html 46.2MB c8431307a174 42 minutes ago /bin/sh -c unzip kodexplorer4.37.zip 32.4MB 3c55f532dca0 42 minutes ago /bin/sh -c #(nop) COPY file:c0ede8b6cbebd456… 13.8MB 138f23faf452 2 hours ago /bin/sh -c #(nop) WORKDIR /var/www/html 0B 84e186c5a38f 2 hours ago /bin/sh -c yum install httpd php php-cli unz… 124MB e88c611d16a0 3 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 3 months ago /bin/sh -c #(nop) LABEL name=CentOS Base Im… 0B <missing> 3 months ago /bin/sh -c #(nop) ADD file:b99efdfca7b4df4ef… 195MB
二、镜像分层的好处
1、分层的好处:
共享资源,节省资源
有多个镜像都从相同的 base 镜像构建而来,那么 Docker Host 只需在磁盘上保存一份 base 镜像;同时内存中也只需加载一份 base 镜像,就可以为所有容器服务了
2、在构建中的截图
三、dockerfile中run的原理
1、目录层级呈现
[root@oldboy layerdb]# pwd /var/lib/docker/image/overlay2/layerdb [root@oldboy layerdb]# tree . ├── mounts │?? └── f2e286474958ee74a06328fadc4a1839a09bb4fdb8ed1f66c649881b6cff5494 │?? ├── init-id │?? ├── mount-id │?? └── parent ├── sha256 │?? ├── 002679450ec12ca6a1d3bc0ef546ba7f85473cc636dbd4d9b903f09f674f7cc6 │?? │?? ├── cache-id │?? │?? ├── diff │?? │?? ├── parent │?? │?? ├── size │?? │?? └── tar-split.json.gz │?? ├── 6a7858bdc1779c5035b615ac39738d0f40a147280f90241829c73af1779ff248 │?? │?? ├── cache-id │?? │?? ├── diff │?? │?? ├── parent │?? │?? ├── size │?? │?? └── tar-split.json.gz │?? ├── 98ce75898ea99aa8be599a25310488bf433b5289ca684180c0cdea545f29f67a │?? │?? ├── cache-id │?? │?? ├── diff │?? │?? ├── parent │?? │?? ├── size │?? │?? └── tar-split.json.gz │?? ├── 9d114c8578095cdd3c1660928c3cca65cd7c241b66fd2a426a3a52845b5cd4ca │?? │?? ├── cache-id │?? │?? ├── diff │?? │?? ├── parent │?? │?? ├── size │?? │?? └── tar-split.json.gz │?? ├── b5e11aae8a8e8fab750bd384393aafa379e21c57c398f5dd4980cd01fcf55b9e │?? │?? ├── cache-id │?? │?? ├── diff │?? │?? ├── size │?? │?? └── tar-split.json.gz │?? └── fbda96ca5467cc519d850984c8f3df6973c5ea9a0f7b22ac516576adcc0a5137 │?? ├── cache-id │?? ├── diff │?? ├── parent │?? ├── size │?? └── tar-split.json.gz └── tmp
2、截图呈现
四、docker的简单总结