A PR adds `COPY . .` and a developer's `.env` file ends up in the image. How do you prevent and remediate?
IntermediateScenarioImage design and Dockerfile decisions
Answer
Situation read → Secrets in a layer are recoverable by anyone with the image.
What I'd do →
- Add
.env,.git,*.pem,id_rsa*to.dockerignore(allow-list style: ignore*, then!src). - Rotate every secret in that file immediately.
- Delete the pushed tags and rebuild; deleting a later layer is not enough.
- Add a CI scan (trivy
--scanners secret, gitleaks).
Why → docker save exposes all layers.
Interview tip → Remediation order: rotate first, clean up second.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner