Course contentsShow
← Software Engineering
Lesson 1425 of 1,93342. Containerization and OrchestrationFree lesson

Container Images and Layers

Learn how container images are built from read-only layers that stack to form a filesystem.

Container Images and Layers

What You'll Learn

You'll understand how container images are built from stacked, read-only layers that efficiently form a complete filesystem.

The Layer Stack Concept

A container image isn't a single monolithic file—it's a collection of read-only layers stacked on top of each other, like transparent sheets of paper. Each layer represents a change to the filesystem: adding files, modifying configurations, or installing software.

Think of it like building a cake: the bottom layer might be your base operating system files, the next layer adds programming language runtime, then application dependencies, and finally your application code on top. Each layer only contains what changed from the layer below it.

Why Layers Matter

When you build an image, each instruction (like copying files or running installation commands) creates a new layer. These layers are:

  • Immutable: Once created, they never change
  • Reusable: Multiple images can share common base layers
  • Efficient: Only changed layers need to be downloaded or stored

For example, if ten applications all use the same base operating system layer, that layer is stored once and shared among all containers.

How Containers Use Layers

When you run a container, the system stacks all the read-only image layers together and adds a thin writable layer on top. Your running application sees a unified filesystem, but writes only go to that top writable layer. When the container stops, that writable layer can be discarded, leaving the original image unchanged.

This is why containers start so quickly—you're not copying an entire filesystem, just mounting existing layers and adding a lightweight writable top.

Key Takeaway: Container images are built from stacked, read-only layers that share common base components, making them efficient to store, transfer, and run while maintaining isolation between containers.