Interview Security & DevSecOps

Why should containers not run as root, and what does running rootless achieve? [Advanced]

Answer

Containers should not run as root because a container breakout, writable host mount, or runtime bug can give an attacker more leverage. Running rootless or as a non-root UID reduces privilege inside the container and reduces blast radius if the application is compromised.

Technical explanation

Root inside a container is not the same as root on the host, but it is still more dangerous than a non-root process.

Rootless containers reduce reliance on privileged daemon behavior and host-level root permissions.

Non-root images require correct file ownership, writable paths for temporary data, and compatible application behavior.

Hands-on example

Dockerfile pattern:

RUN addgroup -g 10001 app && adduser -D -u 10001 -G app app

RUN chown -R app:app /app

USER 10001

In Kubernetes, enforce runAsNonRoot and reject images that require root in restricted namespaces.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Security & DevSecOps interview questions

← All Security & DevSecOps questions