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

Image Layers: The Foundation

How container images are composed of stacked, read-only filesystem layers for efficiency.

Image Layers: The Foundation

What you'll learn: How container images use stacked, read-only filesystem layers to save space and speed up builds.

The Core Idea

A container image isn't one giant file—it's actually a stack of read-only filesystem layers built on top of each other. Each layer represents a set of changes (files added, modified, or removed) from the previous layer. When you run a container, these layers are combined into what appears to be a single filesystem.

Think of it like a transparent overhead projector stack: each transparency (layer) adds something new, and when you look through all of them together, you see the complete picture.

Why Layers Matter

Space efficiency: If ten images all need Ubuntu as a base, that Ubuntu layer is stored once and shared among all ten images. You don't duplicate the same files ten times.

Speed: When pulling an image, you only download layers you don't already have. If you've already got the base OS layer cached, you skip it entirely.

Build optimization: When building images, unchanged layers are reused from cache. Change one line of code? Only the layers after that change need to rebuild.

How It Works

Each layer is identified by a unique hash. Layers stack from bottom (base operating system) to top (your application code). The container runtime merges them using a union filesystem, presenting them as one coherent directory tree to your running container.

When a container writes data, it happens in a thin writable layer on top of the read-only image layers—the image itself never changes.

Key Takeaway: Container images are built from stacked, read-only layers that enable efficient storage, faster transfers, and quick rebuilds by sharing and caching common filesystem changes.