What is a mirror image

An image is a lightweight, executable, standalone package that packages a software runtime environment and software developed based on the runtime environment. It contains the content needed to run a piece of software, including code, runtime libraries, environment variables, and configuration files.

Principle of Image Loading

UnionFS (Joint File System)

Is a layered, lightweight, and high-performance file system that allows changes to the file system to be made layer by layer as a single commit. At the same time, unite serveral directories can be mounted into a single virtual filesystem. The Union filesystem is the basis of a Docker image. The image can be inherited through layers. Based on the basic image, you can make a variety of specific application images.

Docker loading image principle

Docker image is composed of a layer of file systems, such a layer of file systems, then how to achieve file isolation between layers (host machine and container isolation)

In order to implement file layering, rootfs was born. Before introducing bootfs, it is important to know bootfs!

Bootfs (Boot file system) mainly consists of bootloader and kernel. Bootloader mainly boots and loads the kernel. When Linux starts up, bootfs file system will be loaded. This layer is the same as the Linux \ Unix system, which contains the boot loader and the kernel. After the boot loading is completed, the whole kernel is in memory. At this time, the use of memory has been handed over to the kernel by bootfs, and the bootFS will be uninstalled.

Root file System (rootfs) represents distributions of various operating systems. On top of bootfs, it contains standard directories and files such as /dev,/proc, and /etc in typical Linux systems.

Understand the hierarchical

First of all, you can see in the figure below that when you download the Redis image package, you download multiple layers

Root :~ $docker image inspect redis:latest [{"Id": "sha256:02c7f2054405dadaf295fac7281034e998646996e9768e65a78f90af62218be3", "RepoTags": [ "redis:latest" ], "RepoDigests": [ "redis@sha256:552acf4b9f1bdbb6eaee9d02ba533a8f996641c8dd453c7b4ef607525a76cd5a" ], "Parent": "", "Comment": ""," Created ":" the 2021-09-03 T13:26:48. 395038582 z ", "Container" : "3627b30c1a4cf3ef703e0516beee6428efe1b08a5314f5f106b84250635809cb", "ContainerConfig": { "Hostname": "3627b30c1a4c", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "6379/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [" PATH = / usr/local/sbin, / usr/local/bin: / usr/sbin, / usr/bin, / sbin, / bin ", "GOSU_VERSION = 1.12", "REDIS_VERSION = 6.2.5", REDIS_DOWNLOAD_URL = "http://download.redis.io/releases/redis-6.2.5.tar.gz", "REDIS_DOWNLOAD_SHA=4b9a75709a1b74b3785e20a6c158cab94cf52298aa381eea947a678a60d551ae" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD [\"redis-server\"]" ], "Image": "sha256:332cd8bceec776c2152877041d9e60cbaf4ba95504335e888311bcc1444155a7", "Volumes": { "/data": {} }, "WorkingDir": "/data", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": {} }, "DockerVersion": "20.10.7", "Author" : ""," Config ": {" Hostname" : ""," Domainname ":" ", "User" : ""," AttachStdin ": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "6379/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [" PATH = / usr/local/sbin, / usr/local/bin: / usr/sbin, / usr/bin, / sbin, / bin ", "GOSU_VERSION = 1.12", "REDIS_VERSION = 6.2.5", REDIS_DOWNLOAD_URL = "http://download.redis.io/releases/redis-6.2.5.tar.gz", "REDIS_DOWNLOAD_SHA=4b9a75709a1b74b3785e20a6c158cab94cf52298aa381eea947a678a60d551ae" ], "Cmd": [ "redis-server" ], "Image": "sha256:332cd8bceec776c2152877041d9e60cbaf4ba95504335e888311bcc1444155a7", "Volumes": { "/data": {} }, "WorkingDir": "/data", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 105408201, "VirtualSize": 105408201, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/52fc03c3b2ef6e64509de12f75f8e03f438e91e46a3b57848dadb901d2958e28/diff:/var/lib/docker/overlay2 /e68b7712564163bd45a281a4cb70427eccc6809d5fe4b0fc7685df7000511527/diff:/var/lib/docker/overlay2/638d4e1035840a6fa95d50dc 77c622d9ebbb91127a87b75e0f7e23dfe3f6574c/diff:/var/lib/docker/overlay2/ef858710684e26dfcbf497a47f82fc0bf01a6de07841119b6 469c5beb768b73c/diff:/var/lib/docker/overlay2/7c548de738fe0a8c58f8962653ea083c9aa8c1e1b58c2b692245583ca4788326/diff", "MergedDir": "/var/lib/docker/overlay2/d03abe3f1d7ba89cbf16b3e631d2f850215286d01d4243b7045d48c77df7a4db/merged", "UpperDir": "/var/lib/docker/overlay2/d03abe3f1d7ba89cbf16b3e631d2f850215286d01d4243b7045d48c77df7a4db/diff", "WorkDir": "/var/lib/docker/overlay2/d03abe3f1d7ba89cbf16b3e631d2f850215286d01d4243b7045d48c77df7a4db/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:d000633a56813933cb0ac5ee3246cf7a4c0205db6290018a169d7cb096581046", "sha256:bdad86443e47c5665683ac41c1f24f28479d830d7e3cc47d0a337ee5166c7714", "sha256:6a7992ac480029d82b7dbb757d16fe5d023aa283ed32b52267cd1fe9e6b73c49", "sha256:be43d2475cf809c0f2ec31950e849d0f888f3121970fd99196a11a903f8c3820", "sha256:be5818ef2907adfe19be14bf66647b5fb5a2029143f9297f8ce1ff1fd1d35753", "sha256:c54e0c16ea22fa873c12f6a7f3fb4e021bb58d67c292156a6ce6e08637458b7c" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]Copy the code