Chapter 05 • Image Engineering

Working with Docker Images

A Docker Image is an immutable, cryptographic package containing the application binaries, runtime dependencies, and system configuration required to instantiate a container. This chapter explores the underlyingOCI Image Specification, layer deduplication, production tagging strategies, and diagnostic inspection.

1. Anatomy of an OCI Image & Content-Addressable Storage

An image is not a single archive file. It is a bundle consisting of an Image Manifest, a Configuration JSON Blob, and a sequence of gzipped tarball filesystem layers:

1. Image Manifest

JSON descriptor document defining the schema version, target CPU architecture, and a cryptographic list of layer hashes.

2. Config JSON

Stores container execution metadata: environment variables, default exposed ports, working directory, and ENTRYPOINT.

3. Layer Tarballs

Gzipped tarballs holding the filesystem delta (added, changed, or deleted files) created by Dockerfile build steps.

Cross-Image Layer Sharing: Every layer is identified by its SHA-256 cryptographic digest. If you have 10 distinct Node.js microservices all built FROM node:20-alpine, Docker only downloads and stores the 40 MB Node.js base layer once on your host disk. All 10 images share that identical physical layer!

2. Tagging Strategies & The ":latest" Anti-Pattern

When pulling an image without specifying a tag (e.g. docker pull node), Docker defaults to :latest. In production deployments, relying on :latest is a catastrophic anti-pattern:

Tag StrategyExampleRisk LevelProduction Verdict
Implicit Latestnode (equals node:latest)Critical RiskBanned in Production. Upstream changes can break builds silently at 3 AM.
Major Floatingpython:3 or postgres:16Medium RiskAccepts non-breaking minor/patch updates automatically, but risks breaking edge-cases.
Semantic Version (SemVer)postgres:16.2-alpineLow RiskRecommended for Staging & Dev. Pins exact runtime and base distribution.
Immutable Digest Pinningredis@sha256:7f0b...Zero RiskEnterprise Gold Standard. Cryptographically guarantees zero supply-chain drift.

3. Production CLI Workflows

A. Inspecting Layer Breakdown: docker image history

Reveals the exact size and command line instruction that generated each layer:

docker image history --human --no-trunc python:3.12-slim
B. Tagging for Enterprise Registries

The standard image naming format follows: [registry_domain/][namespace/]repository:tag:

# 1. Tag for public Docker Hub:
docker tag my-local-app:v1.0 dockerhub_user/ecommerce-api:v1.0.0

# 2. Tag for AWS Elastic Container Registry (ECR):
docker tag my-local-app:v1.0 123456789012.dkr.ecr.us-east-1.amazonaws.com/ecommerce-api:v1.0.0

# 3. Tag for GitHub Container Registry (GHCR):
docker tag my-local-app:v1.0 ghcr.io/my-org/ecommerce-api:sha-a8f3b2
C. Offline Air-Gapped Image Transfer: save & load

Export an image to a raw tarball to deploy on high-security networks without internet access:

# On development machine connected to the internet:
docker save -o secure-api-v1.tar my-local-app:v1.0

# Transfer tarball via USB / SCP, then load on air-gapped production host:
docker load -i secure-api-v1.tar

Next Up: Writing Production Dockerfiles

In Chapter 6, learn how to construct lean, efficient, and cached container images using modern Dockerfile directives.

Chapter 06: Writing a Dockerfile →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools