Secrets in Dockerfile
Overview
Secrets placed in Dockerfile ENV or ARG instructions are baked into image layers and visible via docker inspect or docker history, even if removed in a later layer. Anyone with pull access to the image can read these secrets.
Remediation
- Use Docker secrets (
--secret) for sensitive values during build - Use multi-stage builds to exclude build-time secrets from final image
- Use
.envfiles with--env-fileat runtime instead of baking into image - Use HashiCorp Vault, AWS Secrets Manager, or Kubernetes Secrets for runtime injection