Skip to content

Docker (containers and images)

Scope: building container images with Docker, running them securely, and running multi-container applications with Docker Compose, mostly for local development and single-host deployments. For running containers on a cluster, see Kubernetes; for building and publishing images in CI, see GitHub Actions. Secrets and supply-chain rules in general/security.md also apply.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 10 Building best practices (Docker Docs): the baseline for Dockerfiles: multi-stage builds, base images, .dockerignore, ephemeral containers, pinning, rebuilding, and advice for each Dockerfile instruction.
  • 8 Docker Security Cheat Sheet (OWASP): the baseline for container security: the daemon socket, users, capabilities, privilege escalation, read-only file systems, resource limits, scanning and supply chain.
  • 8 Docker Compose (Docker Docs): defining and running multi-container applications, including startup order, secrets, multiple Compose files and production use.
  • 7 CIS Docker Benchmark: a consensus hardening benchmark for the Docker host, daemon and containers.
  • 7 NIST SP 800-190, Application Container Security Guide (2017): the security concerns that containers bring, with recommendations for addressing them.

Key rules

Images

Supply chain

Running containers

Compose

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 Docker build checks: built into docker build. Run docker build --check, and add # check=error=true to the Dockerfile so that violations fail the build. JSONArgsRecommended flags shell-form ENTRYPOINT and CMD, and SecretsUsedInArgOrEnv flags secret-like names in ARG and ENV. Checks DOCKER-6, and partly DOCKER-2.
  • 6 Trivy: scans images for known vulnerabilities and embedded secrets. trivy image --exit-code 1 --severity HIGH,CRITICAL fails CI on serious findings. Checks DOCKER-10, and partly DOCKER-2.
  • 6 Docker Scout policy evaluation: docker scout policy evaluates images locally or in CI. Its Severity-Based Vulnerability, Default Non-Root User, No outdated base images and Supply Chain Attestations policies partly check DOCKER-10, DOCKER-1, DOCKER-5 and DOCKER-11.
  • 6 Hadolint: a Dockerfile linter that also runs ShellCheck on RUN instructions, with --failure-threshold to choose which severities fail CI. DL3025 flags shell-form CMD and ENTRYPOINT, DL3002 a final USER root, and DL3006 and DL3007 untagged or latest base images. Checks DOCKER-6, and partly DOCKER-1 and DOCKER-3.

Tutorials and further reading

  • 7 Docker Learn (Docker Docs): the official learning paths, from containers, images, volumes and Compose to building images, multi-stage builds, the build cache and sharing images on Docker Hub.
  • 7 Docker guides (Docker Docs): language-specific guides, such as Node.js, Python, Go and .NET, that containerize an app, set up local development in containers and run tests.
  • 6 Docker Hardened Images (Docker Docs): minimal, continuously patched base images with SBOMs and provenance. The core images are free under Apache 2.0.
  • 5 Use Compose Watch (Docker Docs): sync or rebuild services automatically while you edit code.
  • 5 Development Containers: an open specification for defining a full development environment as a container.