Course contentsShow
← Cloud and Infrastructure
Lesson 976 of 2,98919. Container FundamentalsFree lesson

Union Filesystem Mechanics

How union filesystems merge multiple layers into a single coherent filesystem view.

Union Filesystem Mechanics

What you'll learn: How container images achieve their layered magic by merging multiple read-only layers into a single, coherent filesystem view.


The Core Idea

A union filesystem (sometimes called an "overlay filesystem") is the clever mechanism that takes all those image layers you learned about and presents them to a running container as one unified directory tree. Even though each layer is stored separately on disk, the container sees and interacts with what appears to be a single, normal filesystem.

How It Works

Think of union filesystems like transparent sheets of paper stacked on top of each other:

  • Each sheet (layer) contains some files or directories
  • When you look down through the stack, you see a combined view
  • If multiple sheets have the same file, the topmost sheet wins—you only see that version
  • Lower layers remain untouched and read-only

When a container runs, the union filesystem mounts all the image layers in order (bottom to top) and adds a thin writable layer on top. Any changes the container makes—new files, modified files, deleted files—only affect this top writable layer. The underlying image layers stay pristine and can be shared by many containers.

Why This Matters

Union filesystems enable:

  • Layer sharing: Ten containers from the same image share the same base layers
  • Fast starts: No need to copy gigabytes; just mount existing layers
  • Efficient storage: Common layers (like an OS base) are stored once
  • Image immutability: Original layers never change, ensuring consistency

Key Takeaway: Union filesystems merge multiple read-only image layers and a writable container layer into a single filesystem view, enabling efficient storage, fast container creation, and layer reuse across multiple containers.