Dockerfile Best Practices
Cheat sheet · https://pcornel.dk/topic.php?topic=6123
Answer
Dockerfile best practices: small trusted base images, multi-stage builds, pinned versions, combined RUN steps that clean caches, a non-root USER, COPY instead of ADD, a .dockerignore, and an explicit HEALTHCHECK/ENTRYPOINT.
Remember
Never bake secrets into images — use build secrets. Order layers for caching. Use exec-form ENTRYPOINT so signals reach the process.
First checks
hadolint Dockerfile— Dockerfile lintdocker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
Commands
docker stop
Verify in this order
Dockerfile → build context → layers → image
Where it usually breaks
Shell-form ENTRYPOINT runs the app under /bin/sh, which does not forward SIGTERM, so stops take the full timeout.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6123