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































