Understanding Container Images: Layers, Tags, and Digests
Container images are the building blocks of self-hosted apps. Understanding layers, tags, and digests helps you manage them effectively.
What Is a Container Image?
An image is a read-only template that contains everything needed to run an application: code, runtime, libraries, and configuration.
Layers
Images are built in layers. Each instruction in a Dockerfile creates a new layer.
FROM node:20-alpine # Layer 1: Base OS + Node.js
COPY package.json . # Layer 2: Package file
RUN npm install # Layer 3: Dependencies
COPY . . # Layer 4: Application code
Why Layers Matter
Tags
Tags are human-readable labels for specific image versions.
postgres:16.2-alpine
└ image name └ tag
Common Tag Patterns
Never Use :latest in Production
:latest changes unpredictably. Yesterday it was 16.1, today it's 16.2. Pinned versions prevent surprise breakage.
Digests
A digest is a SHA-256 hash of the image. Immutable and unique.
postgres@sha256:abc123...
Use digests for maximum reproducibility. The same digest always produces the same image.
Multi-Architecture Images
Modern images support multiple CPU architectures:
Docker/Podman automatically pulls the correct architecture.
Image Size
Smaller images are better:
Compare: postgres:16 (400 MB) vs postgres:16-alpine (80 MB)
Managing Images
List images
docker images
Remove unused
docker image prune (removes dangling images)
docker image prune -a (removes all unused images)
Check size
docker system df
Regularly prune unused images to reclaim disk space.