Docker Container Security Testing: Capabilities & Escapes
How penetration testers test Docker and container runtime security: --privileged flags, mounted docker.sock, dangerous Linux capabilities, and root users.
DevSecOps · By Thimmagurudu Bathini, CTO · Published · 5 min read
What Happens When RCE Meets a Weak Container
Containers are not full virtual machines—if a containerized web app suffers an RCE or command injection, weak container runtime flags decide whether the attacker stays trapped or escapes to the underlying host node. Testing container hardening closes that escalation bridge.
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]Four Runtime Flags That Enable Host Escape
| Runtime Setting | Escape / Escalation Risk | Secure Baseline |
|---|---|---|
| --privileged: true | Disables isolation and exposes host devices for trivial escape | Never use --privileged in app workloads |
| /var/run/docker.sock Mounted | Container can spin up a root host-mounted container immediately | Remove Docker socket mounts; use rootless/Kaniko builders |
| CAP_SYS_ADMIN / CAP_NET_RAW | Allows mount tricks, cgroup escapes, or ARP/DNS spoofing | Drop ALL capabilities and add back only minimal required caps |
| UID 0 (Root) + Writable FS | App runs as root and can modify binaries or persist | Set non-root USER, readOnlyRootFilesystem: true, no-new-privileges |
Auditing Capabilities, Root UIDs & Pod Specs
- Inspect Docker Compose, ECS task definitions, and Kubernetes PodSecurity specs for privileged mode and hostPath mounts.
- Check whether containers run as UID 0 or retain CAP_SYS_ADMIN / CAP_SYS_PTRACE.
- Verify container images for minimal base OS (distroless/alpine) and patched OS packages.
- Test egress network policies from inside running pods to confirm metadata and internal control planes are blocked.
Enforcing Non-Root & Read-Only RootFS
Run containers as non-root with read-only root filesystems, drop all Linux capabilities, and never mount /var/run/docker.sock inside application containers.
Test your container runtime and Kubernetes workloads from ₹36,000 + 18% GST. Request a scoped proposal →
Container Security Testing Questions
Does a container vulnerability scan catch runtime escape paths?
Image scanners only list CVEs in packages; they miss runtime flags like privileged: true, hostPath mounts, and RBAC escapes.
Can BERRY9 test both containers and Kubernetes clusters?
Yes—under our DevSecOps and infrastructure security services starting from ₹36,000 + 18% GST.