Docker 的层级(layer)概念
1.镜像(images)与层级(layers):
Docker 镜像是由多个文件系统(只读层)叠加而成,每个层仅包含了前一层的差异部分。当我们启动一个容器的时候,Docker 会加载镜像层并在其上添加一个可写层。容器上所做的任何更改,譬如新建文件、更改文件、删除文件,都将记录与可写层上。容器层与镜像层的结构如下图所示。
(A Docker image is built up from a series of layers. Each layer is only a set of differences from the layer before it. The layers are stacked on top of each other. When you create a new container, you add a new writable layer on top of the underlying layers. This layer is often called the “container layer”. All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin writable container layer. The diagram below shows a container based on the Ubuntu 15.04 image.)
2.容器(container)与层级(layers):
容器与镜像最大的区别就在于可写层上。如果运行中的容器修改了现有的一个已存在的文件,那该文件将会从可写层下的只读层复制到可写层,该文件的只读版本仍然存在,只是已经被可写层中该文件的副本所隐藏。其中,多个容器共享镜像的结构如下所示。
(The major difference between a container and an image is the top writable layer. All writes to the container that add new or modify existing data are stored in this writable layer. When the container is deleted, the writable layer is also deleted. The underlying image remains unchanged.
Because each container has its own writable container layer, and all changes are stored in this container layer, multiple containers can share access to the same underlying image and yet have their own data state. The diagram below shows multiple containers sharing the same Ubuntu 15.04 image.)
参考资料:
(1).https://docs.docker.com/