Checklist
- Run as non-root: set
user: "1000:1000"when possible. - Avoid docker.sock: mounting it gives host-level control (treat as privileged infrastructure).
- Don’t expose sensitive ports: bind DB ports to
127.0.0.1or internal networks. - Pin images: avoid
latest/ missing tags; prefer version tags or digests. - Avoid privileged / ALL caps: minimize privileges and capabilities.
- Add healthchecks + restart: prevents silent failures and flapping services.
- Keep secrets out of YAML: use
${VAR}+.env(gitignored) or Docker secrets.
Automate the checklist
Run ConfigSentry locally:
npx configsentry ./docker-compose.yml
CI gating (only HIGH):
npx configsentry ./docker-compose.yml --severity-threshold high
More: Docker Compose linter