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.
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
- What are Linux capabilities, and why drop them in containers? [Advanced]
- What are Kubernetes Pod Security Standards (privileged, baseline, restricted)? [Advanced]
- How do you prevent privilege escalation in a Kubernetes cluster? [Advanced]
- What is the difference between authentication and authorization? [Advanced]
- What is certificate management, and how do tools like cert-manager help? [Advanced]
- What is the difference between symmetric and asymmetric encryption? [Advanced]
- What is the difference between encoding, encryption, and hashing? [Advanced]
- What is encryption at rest versus in transit, and how do you ensure both? [Advanced]