liveBook · Manning

Copy-on-write

As explained in Kubernetes in Action, Second Edition

A copy-on-write mechanism preserves shared data until a modification causes a private copy to be created.

Copy-on-write (CoW) preserves shared container image files until an application changes one. The filesystem combines read-only image layers with a private read/write layer. section 2.1.2

Changing a shared file

Containers A and B can read the same image-layer files. If A changes a file, Docker copies the entire file into A’s read/write layer and changes that copy, so B remains unaffected. Deleting a file marks it deleted above the lower layer rather than removing it from the image. section 2.1.2

Account for these operational consequences:

  • Changing permissions or ownership also copies the entire file, so modifying large or numerous files can significantly increase writable-layer usage. section 2.1.2
  • Each container has its own writable layer, which isolates changes even when containers share image layers. section 2.1.2
Figure 2.8 Containers can share image layers.
figure

Use the layer diagram to trace how containers share image data while retaining separate writable changes. section 2.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains layered reads, whole-file copying, deletion markers, and storage consequences without detailing filesystem-driver internals.
Examples
Uses three containers sharing layers, file modification, file deletion, and permission changes as concrete cases.
What you can do after
Evaluate how container file operations affect isolation and writable-layer storage.
How it connects
Connects container images, image layers, container filesystems, writable layers, and container isolation.

Also explained in

Compare how 5 books explain copy-on-write →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.