liveBook · Manning

Container image

As explained in Fast by Default

A container image is a packaged artifact containing application code, dependencies, and operating-system files needed to run a container.

A container image packages application code, dependencies, and operating-system files into one artifact that can be pulled and started on a server. Images are built from immutable layers, each recording filesystem changes from a build step. section 8.2 section 8.2.1

Image size affects more than storage: large images take longer to pull during rollouts, delay new instances in auto-scaling or serverless environments, slow builds and deployments, and lengthen the feedback loop. section 8.2 section 8.6

Analyze and reduce an oversized image systematically:

  • Use docker history, or an equivalent container tool, to identify the largest build layers and the commands that created them. section 8.2.1
  • Use Dive to inspect the files inside a large layer and identify build tools, package caches, documentation, utilities, or unused dependencies. section 8.2.1
  • Do not rely on deleting files in a later layer: earlier immutable layers still contain them and every deployment still pulls them. section 8.2.1
  • Separate compilation from production packaging with a multi-stage Dockerfile, then copy only the runtime dependencies and application files into a smaller production image. section 8.2.1

Checkout API rollout

A Kubernetes checkout API used a 2.1GB image across 12 nodes, making pulls dominate a 90-second deployment. Analysis found a 1.3GB installation layer containing build tools and caches, plus 412MB of unnecessary base-image content. A multi-stage build used a full Python image for compilation and python:3.11-slim for production. section 8.2 section 8.2.1

Listing 8.6 Inspecting container image layers with docker history
docker history --human --no-trunc your-image:tag #A

Inspect layer sizes directly with docker history before browsing their file contents with Dive. section 8.2.1

How Fast by Default covers it

How deep it goes
Explains packaging, immutable layers, inspection tools, and multi-stage remediation, stopping short of complete deployment automation.
Examples
Uses a Kubernetes checkout API, docker history output, Dive inspection, and a Python multi-stage Dockerfile.
What it assumes
Assumes familiarity with container builds and Dockerfiles while defining images, layers, and their operational effects.
What you can do after
Diagnose oversized images with docker history and Dive, then reduce production content through multi-stage builds.
How it connects
Connects container images with Dockerfiles, container layers, dependency analysis, Kubernetes, auto-scaling, and serverless environments.

Also explained in

Compare how 32 books explain container image →

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.