Skip to main content
InterviewHubPRO
Section Overview
Q18

Question 18 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

36%
Docker & Containers (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Why is running containers as root a major security vulnerability, and how do you secure runtime privileges?

senior LevelCode ExampleSecurity & AuthDocker & ContainersSystem Design

In Simple Words: By default, UID 0 inside a container is UID 0 on the host Linux kernel unless User Namespaces are enabled. If an attacker achieves Remote Code Execution (RCE) inside a container running as root:

  • Any breakout (via kernel vulnerability, container escape, or mounted Docker socket) grants root access to the entire host server.

Hardening Rules:

  1. Always create and switch to a non-privileged user in the Dockerfile:
    dockerfile
    RUN addgroup -S appgroup && adduser -S appuser -G appgroup
    USER appuser
    
  2. Run container with read-only root filesystem:
    bash
    docker run --read-only --tmpfs /tmp --user 10001:10001 my-app
    
  3. Drop all kernel capabilities:
    bash
    docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE my-app