Java Zero to All All questionsPractise free
Interview questions › DevOps: Docker, Kubernetes & Helm › Docker & Containers

Why run as non-root and what other hardening do you apply to a production image?

Level III · MidDocker & Containers
Short answer

By default containers run as root (UID 0); a compromised app then has root inside the container, easing container escape and host access, so you create and switch to a non-root user (USER appuser) — many cluster policies require it.

Explanation

Beyond that: pin a specific minimal base image (distroless/Alpine/JRE-only) rather than latest, run with a read-only root filesystem and drop Linux capabilities, scan images for CVEs in CI, and never bake secrets into layers since they persist in image history even if later deleted.

Common mistakes
  • Running as root.
  • Leaving secrets in image layers.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Docker & Containers.

Practise free

More on Docker & Containers