Guide
Premium
Intermediate
Real Projects

Docker Images in Production: Multi-stage Builds, BuildKit Caching, Distroless and Reproducible Builds

A practical guide to stop treating the Dockerfile as an afterthought: how layer caching actually works and why copying source before manifests invalidates your dependency install on every commit, complete multi-stage builds for Python (with uv), Node (with pnpm and pruning) and Go, BuildKit cache mounts that turn ninety seconds of installing into three, build secrets with --mount=type=secret instead of ARG (which is written into docker history forever), registry caching in CI and the mode=max flag almost everyone forgets that leaves the expensive stages uncached, COPY --link and when not to use it, the four base image families (Debian slim, Alpine and the musl trap with Python, distroless, and hardened images such as Wolfi/Chainguard) with real selection criteria, operational practices (numeric UID for runAsNonRoot, exec form so SIGTERM arrives, read-only root filesystem, OCI labels), and provenance, SBOM, digest pinning and SOURCE_DATE_EPOCH for reproducible builds. With eight recurring mistakes, a production checklist and an FAQ. Expanded September 2026 edition: multi-platform builds (QEMU versus cross-compilation with TARGETPLATFORM and native runners, and the index you break by pushing one architecture separately), docker buildx bake for describing the build as configuration with target inheritance and test stages that export artifacts, how to measure size properly (compressed versus uncompressed, shared layers and a CI size budget), vulnerability scanning without noise by separating base from dependencies with --ignore-unfixed, VEX and daily rescans of what is already deployed, keyless Sigstore signing and identity verification at admission with Kyverno and mutateDigest, debugging shell-less images with ephemeral containers and /proc/1/root, the three CI cache backends with the four real causes of a cache miss, the start and stop contract with the orchestrator (exec form, PID 1, STOPSIGNAL, HEALTHCHECK versus probes and GOMEMLIMIT), the registry as infrastructure with retention policies, pull-through caching and the trap of expiring untagged images that belong to an index, a full case study from 14 minutes and 1.4 GB to 95 seconds and 180 MB with per-step numbers, four more mistakes you only see in production, an expanded FAQ and a glossary. Second September 2026 expansion: building without a daemon in CI (Kaniko archived in June 2025, rootless BuildKit with the Kubernetes driver, Buildah, and long-lived remote builders that keep the cache warm), when not to write a Dockerfile with buildpacks, ko and jib — and why pack rebase changes the cost of patching a fleet of hundreds of images —, private dependencies without leaking credentials (mounted secrets versus ARG, the GOPRIVATE=* trap, and RUN --network=none to prove a step is hermetic), mutable tags versus promotion by digest with immutable tags and automated base-image digest advancement via Renovate, and cold start in depth: the 76% of startup spent pulling, parallel kubelet pulls, PromQL to measure it, lazy pulling with eStargz and SOCI, and the pre-pull DaemonSet that is usually the boring, correct answer.

57 minutes read
Josué García
2 views

Verificando acceso...

Loading comments...

Related Resources

Guía
PREMIUM

API Errors with Problem Details (RFC 9457): One Standard Format, Stable Types, and Clients That Stop Parsing Strings

A practical guide to standardising your API errors with Problem Details (RFC 9457): the anatomy of type, title, status, detail and instance, extension members, validation with multiple errors, centralised FastAPI implementation, a TypeScript client that branches on type, security (what not to reveal), OpenAPI documentation, contract tests, common mistakes and an adoption checklist. With code in Python, TypeScript, YAML and HTTP. Expanded edition of 12 October 2026: the type catalog as a contract (stable URIs, about:blank, the IANA registry and evolution rules), a problem registry in code that generates the docs, domain exceptions and a central FastAPI handler with headers and localization, a robust TypeScript client with retries, Retry-After and jitter, per-type metrics and alerts, migrating without breaking clients, Spring, ASP.NET and Node, async errors, batches and idempotency, a case study, FAQ and glossary. Expansion of October 16, 2026: the boundaries almost nobody covers: errors generated by gateways and proxies (nginx and Envoy local_reply_config), a client that survives intermediary HTML responses, errors in the middle of an SSE or NDJSON stream with a terminal frame and resume cursor, partial failures in batches, disciplined design of extension members with extra="forbid", linting with Spectral, fuzzing with Schemathesis, client tests with MSW and a runbook for spikes in one problem type.

Guía
PREMIUM

API Versioning and Contract Testing: Safe Changes, OpenAPI in CI, Pact, and Retiring Endpoints with Sunset

A practical guide to changing your APIs without breaking the people who consume them: why compatibility rules invert between the request and the response —and why widening a returned enum breaks clients even though you are "only adding"—, the tolerant reader pattern in Pydantic with an escape hatch and a metric, OpenAPI generated from the code and diffed on every pull request with oasdiff (including the git diff --exit-code step without which the whole check is theatre), consumer-driven contract testing with Pact: type matchers instead of literal values, well-designed provider states, version selection with deployed_or_released, and the gate that actually makes it safe, can-i-deploy paired with record-deployment. It also covers rolling this out without stopping the factory using pending and WIP pacts, bi-directional contracts when the provider is a third party, the three versioning strategies with their real operational costs, why versioning the whole API for a single endpoint guarantees nobody migrates, retiring versions with the Deprecation (RFC 9745) and Sunset (RFC 8594) headers plus the migration Link, the per-consumer metric without which no sunset date is ever met, brownouts returning 410 Gone before the final shutdown, and the BACKWARD, FORWARD and FULL compatibility modes for event schemas. With production-ready code in Python, YAML, Bash and PromQL, eight recurring mistakes, a production checklist, FAQ and glossary. It also extends the contract beyond the happy path: errors with RFC 9457 (problem+json), cursor pagination and defaults as part of the contract, the expand/contract pattern for renaming a field across database and API with no maintenance window, governance with Spectral, buf breaking for gRPC and Protobuf, GraphQL schema evolution with @deprecated and real per-field usage, and semantic versioning of generated SDKs. It also covers the contracts that never show up in the schema and break just as hard: outbound webhooks with the version pinned on the subscription, HMAC signing with a timestamp window and key rotation, Idempotency-Key for safe POST retries, the RateLimit and RateLimit-Policy headers —and why lowering a limit is a breaking change—, and OAuth scopes, the blind spot no OpenAPI diff will ever catch.

Guía
PREMIUM

Architecture Decision Records (ADRs): Document the Why Behind Your Technical Decisions

A practical guide to recording architecture decisions with ADRs: what they are and are not, when to write one, a template covering context, alternatives and consequences, a lifecycle with statuses and supersession, and automation with a creation script and a CI validator. With Bash, Python and YAML code, common mistakes and a checklist. Expanded edition of October 2, 2026: writing context with evidence, alternatives without straw men and a weighted decision matrix with sensitivity analysis, Nygard, MADR 4 and Y-statement templates, the advice process with roles, CODEOWNERS and a PR template, the boundary between ADRs, RFCs, design docs and runbooks, ADRs as executable architecture with import-linter and fitness tests, generated index and supersession graph, scheduled reviews with Review-by, two complete annotated ADRs, ADRs at scale in monorepos and multi-repo setups, adoption through retroactive ADRs, ADRs as context for coding assistants, health metrics, advanced mistakes, FAQ and glossary.