Small base, multi-stage, non-root user, one layer per concern, .dockerignore, health check, pinned digests.
A Dockerfile that ages well
Pin the base image
FROM ubuntu:24.04@sha256:...notubuntu:latest. Latest moves; digests do not.Multi-stage always
Build in one stage,
COPY --from=builderonly the artifact. Cuts image size by 80-95%.Non-root user
USER appuser. Root in the container shares the host kernel capabilities.Group RUN commands
RUN apt-get update && apt-get install -y X && rm -rf /var/lib/apt/lists/*= one layer, minimal size.`.dockerignore`
Exclude
node_modules,.git,*.log. A copy that pulls.gitmultiplies the image 10×.HEALTHCHECK
HEALTHCHECK CMD curl -f http://localhost/ || exit 1. Kubernetes and CI rely on it.