Course contentsShow
← Security
Lesson 1632 of 3,05233. Container SecurityFree lesson

Container Image Anatomy and Layers

Understanding image layers, manifests, and how images are built from base images through layered filesystems.

Container Image Anatomy and Layers

What you'll learn: How container images are constructed from layered filesystems and why this matters for security.

The Layered Structure

A container image isn't a single monolithic file—it's a stack of read-only layers built on top of each other, like transparent sheets in an overhead projector. Each layer represents a filesystem change from a specific instruction in the image's Dockerfile (e.g., RUN, COPY, ADD).

When you start with a base image like ubuntu:20.04 and add your application, you're not modifying the base—you're creating new layers on top of it. The final running container adds a thin writable layer on top of all these read-only layers.

The Image Manifest

The manifest is like a blueprint or table of contents. It's a JSON file that describes:

  • Which layers compose the image (by their cryptographic hashes)
  • The order layers must be stacked
  • Configuration metadata (environment variables, entry point, etc.)

Each layer is identified by its content hash (usually SHA-256), enabling verification and deduplication across images.

Security Implications

This layered architecture has critical security ramifications:

  1. Hidden secrets persist: If you COPY a password file in layer 3 and delete it in layer 4, it still exists in layer 3—anyone can extract it.

  2. Shared base vulnerabilities: Multiple images sharing ubuntu:20.04 share its vulnerabilities. Patch the base once, but you must rebuild all dependent images.

  3. Layer inspection: Attackers (and defenders) can examine every layer independently to find misconfigurations or embedded credentials.

  4. Immutability: Read-only layers can't be tampered with at runtime without detection, but vulnerabilities baked into those layers can't be hot-patched either.

Key Takeaway: Container images are transparent stacks of immutable filesystem layers tracked by manifests—understanding this structure is essential for finding hidden secrets, managing vulnerabilities, and securing the supply chain.