五、理解镜像层

history命令查看镜像层

例:docker history hello-world

显示镜像hello-world分三层,其中两个空层

查看镜像文件

镜像存放在imagedb里

一般在image/overlay2/imagedb/content/sha256下

 

打开一个镜像文件查看其内容:

cat f09fe80eb0e75e97b04b9dfb065ac3fda37a8fac0161f42fca1e6fe4d0977c80

{

        "architecture": "amd64",

        "config": {

                             "Hostname": "",

                             "Domainname": "",

                             "User": "",

                             "AttachStdin": false,

                             "AttachStdout": false,

                             "AttachStderr": false,

                             "Tty": false,

                             "OpenStdin": false,

                             "StdinOnce": false,

                             "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],

                             "Cmd": ["/hello"],

                             "ArgsEscaped": true,

                             "Image": "sha256:a6d1aaad8ca65655449a26146699fe9d61240071f6992975be7e720f1cd42440",

                             "Volumes": null,

                             "WorkingDir": "",

                             "Entrypoint": null,

                             "OnBuild": null,

                             "Labels": null

        },

        "container": "8e2caa5a514bb6d8b4f2a2553e9067498d261a0fd83a96aeaaf303943dff6ff9",

        "container_config": {

                             "Hostname": "8e2caa5a514b",

                             "Domainname": "",

                             "User": "",

                             "AttachStdin": false,

                             "AttachStdout": false,

                             "AttachStderr": false,

                             "Tty": false,

                             "OpenStdin": false,

                             "StdinOnce": false,

                             "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],

                             "Cmd": ["/bin/sh", "-c", "#(nop) ", "CMD [\"/hello\"]"],

                             "ArgsEscaped": true,

                             "Image": "sha256:a6d1aaad8ca65655449a26146699fe9d61240071f6992975be7e720f1cd42440",

                             "Volumes": null,

                             "WorkingDir": "",

                             "Entrypoint": null,

                             "OnBuild": null,

                             "Labels": {}

        },

        "created": "2019-01-01T01:29:27.650294696Z",

        "docker_version": "18.06.1-ce",

        "history": [{

                             "created": "2019-01-01T01:29:27.416803627Z",

                             "created_by": "/bin/sh -c #(nop) COPY file:f77490f70ce51da25bd21bfc30cb5e1a24b2b65eb37d4af0c327ddc24f0986a6 in / "

        }, {

                             "created": "2019-01-01T01:29:27.650294696Z",

                             "created_by": "/bin/sh -c #(nop)  CMD [\"/hello\"]",

                             "empty_layer": true

        }],

        "os": "linux",

        "rootfs": {

                             "type": "layers",

                             "diff_ids": ["sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3"]

        }

}

 

----其中,history数组内,标识了镜像的历史记录(与history命令内容对应)

----rootfs的diff_ids中,对应了依赖使用中镜像层文件(history命令中size大于0的层)

 

查看镜像层文件

层文件在layerdb里

ll /var/lib/docker/image/overlay2/layerdb/sha256

#镜像层文件内结构:

五、理解镜像层_第1张图片

镜像与容器总结

一个镜像就是一层层的layer层文件,盖楼而成,上层文件叠于下层文件上,若上层文件有与下层文件重复的,则覆盖掉下层文件重复的部分,如下图:

五、理解镜像层_第2张图片

 

---------初始挂载时读写层为空。

---------当需要修改镜像内的某个文件时,只对处于最上方的读写层进行了变动,不复写下层已有文件系统的内容,已有文件在只读层中的原始版本仍然存在,但会被读写层中的新版本文件所隐藏,当 docker commit 这个修改过的容器文件系统为一个新的镜像时,保存的内容仅为最上层读写文件系统中被更新过的文件。

---------联合挂载是用于将多个镜像层的文件系统挂载到一个挂载点来实现一个统一文件系统视图的途径,是下层存储驱动(aufs、overlay等) 实现分层合并的方式。

你可能感兴趣的:(docker)