Learn Docker:Fundamentals of Docker 19.x
上QQ阅读APP看书,第一时间看更新

Copy-on-write

Docker uses the copy-on-write technique when dealing with images. Copy-on-write is a strategy for sharing and copying files for maximum efficiency. If a layer uses a file or folder that is available in one of the low-lying layers, then it just uses it. If, on the other hand, a layer wants to modify, say, a file from a low-lying layer, then it first copies this file up to the target layer and then modifies it. In the following screenshot, we can see a glimpse of what this means:

Docker image using copy-on-write

The second layer wants to modify File 2, which is present in the Base Layer. Thus, it copies it up and then modifies it. Now, let's say that we're sitting in the top layer of the preceding screenshot. This layer will use File 1 from the Base Layer and File 2 and File 3 from the second layer.