Pcornel
Containers · Images & Registries

Dockerfile Best Practices

Cheat sheet · https://pcornel.dk/topic.php?topic=6123

Back to the Topic

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 lint
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker 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

Confirmation

Confirm action

Continue?