AlgoViz

Image layers, writable state and copy-up

medium 7 min

A container image supplies read-only lower layers.

Video lesson · Chapter 1 of 4

A one-byte edit copies a large file

0:00 / 2:16

Theory

Read or listen first. About 2 min.

What it is

A container image supplies read-only lower layers. OverlayFS presents them together with an upper writable layer. Modifying a lower-layer file can require copying its data into that upper layer, depending on the operation and filesystem features. The merged pathname looks unchanged even when the physical cost of the first write is substantial.

Why it exists

A startup script updates a small field in a large prebuilt file. Fresh containers show slow first writes and increased node disk usage, while later edits are fast. Compare upper-layer growth before and after the first edit. Separate mutable state into a suitably sized volume or a small independent file and repeat on a fresh instance.

If later edits cost just as much, the steady-state storage path may dominate over the initial copy-up.

A one-byte edit copies a large file

Image layer → Writable upper layer (copy up on first edit). Writable upper layer → Backing store (allocate blocks)
Image layer → Writable upper layer (copy up on first edit). Writable upper layer → Backing store (allocate blocks)

Inside this chapter

Copy-on-Write for storage layers
Unchanged image data can be shared between containers. When a container modifies a lower file, a private upper copy may be required. Measure first-write cost separately.
OverlayFS internals
OverlayFS combines lower directories and an upper directory into one view. Whiteouts hide removed lower names without deleting the original image content.
The conceptual model of Docker images vs. containers
An image describes immutable filesystem content and configuration. A container adds an execution environment and writable state. Replacing it can discard data held only in that writable layer.
Linux Capabilities (CAP_NET_ADMIN, CAP_SYS_ADMIN)
Capabilities split privileged operations into categories. Diagnose a denied operation against the documented minimum privileges of the workload and preserve least privilege.
Seccomp profiles for containers
A seccomp profile restricts syscall use independently of file ownership. A workload upgrade can need a different documented interface. Confirm the intended policy when analyzing a denial.
Container runtimes: runc, containerd, CRI-O
High-level runtime services manage images and lifecycle, while a low-level runtime constructs the isolated process. Identify which layer failed when a container never reaches application startup.
Container Networking Interface (CNI) basics
CNI plugins configure network connectivity for a workload. An address assignment failure or incomplete setup can leave a healthy image unable to join its network.

How it works

Step through the idea, or press Play.

Step 1 of 4

Resolve a read. A merged pathname finds an unchanged file in the read-only lower layer.

Understand it

Worked incident

A one-byte edit copies a large file

ObservationNew upper-layer data (MiB)Interpretation
Baseline0A fresh upper layer contains no copy.
Incident256The first data edit copies a 256 MiB lower file into the upper layer.
After intervention1Keep the edited field in a small mutable file and compare first-write work.
Illustrative measurements from the same workload at three checkpoints.

Choose the next investigation

If later edits cost just as much, the steady-state storage path may dominate over the initial copy-up.

Summary

The whole topic in one minute.

Copy-up can materialize an entire lower file. Later writes target the existing upper copy.

If later edits cost just as much, the steady-state storage path may dominate over the initial copy-up.

Sources