You find a database password baked into a Docker image layer that's in a public registry. What do you do?

IntermediateScenarioSecurity incidents
Answer

Situation read → Removing it in a later layer doesn't help; every layer is downloadable. Anyone who pulled the image has the password.

What I'd do →

  1. Rotate the password now and check database logs for logins from unknown sources.
  2. Make the repository private or delete the affected tags.
  3. Find how it got in: ENV DB_PASSWORD=..., a copied .env file, or ARG values (visible in docker history).
docker history --no-trunc myorg/api:1.4.0 | grep -i pass
  1. Fix the build: add .env to .dockerignore, use BuildKit secret mounts for build-time secrets, and inject runtime secrets from Secrets Manager or Kubernetes Secrets.
  2. Scan images for secrets in CI (Trivy has a secret scanner) and fail the build on findings.

Why → Image layers are permanent history; the only real fix is rotation.

Interview tip → Mention that ARG values appear in docker history; many people think they're safe.

All Real-World Interview questions Roadmap: Interview readiness

More on Security incidents