A focused, do-this-now checklist for turning a typical Dockerfile into a small,
secure, production-grade image — plus a fully worked before/after and a .dockerignore
starter. Cheap, fast, and instantly verifiable: the kind of task an agent should
just apply.
FROM node:20-slim →FROM node:20-slim@sha256:.... Reproducible + tamper-evident.
-slim, -alpine, or gcr.io/distroless.minimal runtime stage. Keeps build tools out of the shipped image.
USER app. Never run as root..dockerignore so secrets, .git, .env,node_modules, and CI files never enter the image.
COPY .env or ARG/ENV a secret — itpersists in image history. Use build secrets / runtime env.
(apt-get ... && rm -rf /var/lib/apt/lists/*).
layer-cache reuse.
WORKDIR, not cd. Pin file ownership with --chown.HEALTHCHECK.--read-only + tmpfs) where possible.trivy image, docker scout) in CI; fail on HIGH.CMD (exec form, ["node","server.js"]), not shell form.Dockerfile.before — a common, insecure Dockerfile (root, fat base, secrets leak).Dockerfile.after — the hardened, multi-stage, non-root version of the same app..dockerignore — a sensible starter that keeps secrets and cruft out.CHECKLIST.md — the checklist above as a standalone file to drop in your repo.Docker. That's it.
Get the full Dockerfile Hardening Checklist and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.