Cloud and Container Basics
Inside a container started from an image, the configuration file /etc/app.conf, which is part of the image, is modified. Which of the following correctly describes what happens with Docker's usual storage mechanism (such as overlay2)?
- AThe file is copied into the container's writable layer and then modified, so the image and other containers are not affected
- BThe file in the image layer is modified directly, so other containers started from the same image also see the new contents
- CImage layers are read-only, so files contained in the image cannot be modified, and the write fails with an error
Show answer and explanation
Answer: A. The file is copied into the container's writable layer and then modified, so the image and other containers are not affected
A container's file system presents the read-only image layers with a writable layer for that container stacked on top, as a single tree. The first time a file in a lower layer is modified, it is copied into the writable layer, and from then on the copy is used (copy-on-write). The image layers therefore stay unchanged, and other containers sharing the same image are not affected. Because the first copy of a large file takes time, data that is written frequently, such as database data, is placed in a volume.
- A. Correct. On the first write, the file is copied into the writable layer.
- B. Image layers are read-only and shared by several containers, so they are not modified directly.
- C. The write does not fail; it happens after the file is copied into the writable layer.