liveBook · Manning

Image layer

As explained in Fast by Default

A layer is an immutable filesystem-difference record that contributes to a container image.

An image layer is an immutable record of filesystem changes made by one image-build step. Layers combine application code, dependencies, and operating-system files into a container image; later deletions cannot remove data stored in earlier layers. section 8.2.1

Use layer analysis to find and prevent image-size problems:

  • Run docker history, or its Podman equivalent, to identify which build commands created the largest layers. section 8.2.1
  • Use Dive to browse each layer's files and determine which directories, caches, or build tools consume space. section 8.2.1
  • Combine installation and cleanup in the same build step, or use a multi-stage build, because later cleanup leaves earlier-layer data in the image. section 8.2.1

Checkout API image

A checkout API had a 1.3GB installation layer containing system packages, compiled extensions, build tools, and package caches; its full Debian base added another 412MB. A builder stage can retain those tools while the production stage copies only installed dependencies into a slim runtime image. section 8.2.1

How Fast by Default covers it

How deep it goes
Defines immutable filesystem changes and demonstrates inspection, but stops short of layer-storage internals.
Examples
Uses a checkout API, docker history output, Dive exploration, and a Python multi-stage Dockerfile.
What you can do after
Diagnose oversized image layers with docker history or Dive and reduce production contents with multi-stage builds.
How it connects
Connects image layers with container images, Dockerfiles, base images, package caches, and multi-stage builds.

Also explained in

Compare how 7 books explain image layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.