Multi-stage builds, non-root user, pinned digests, small base images, and a
.dockerignorethat is not empty.
Docker that ages well
Multi-stage builds
Build in one stage, copy only the artifact into the final image. Saves hundreds of MB.
Non-root user
USER appuserin the final stage. Root containers are host-kernel risks.Pinned base images
FROM ubuntu:24.04@sha256:...instead ofFROM ubuntu:latest. Latest moves; digests do not.Small base images
alpineordistrolessfor the final stage. Smaller = faster pull, fewer CVEs.`.dockerignore`
Exclude
node_modules,.git,*.log. A copy that includes.gitmultiplies image size by 10.Healthcheck
HEALTHCHECK CMD curl -f http://localhost/ || exit 1. Kubernetes uses it; CI uses it.