Skip to main content

Overview

Docker uses Linux kernel namespaces, cgroups, capability dropping, Seccomp, and SELinux/AppArmor to isolate containers. Understanding both the protections and their weaknesses is essential for container security assessments.
Container escape techniques described here are for authorized penetration testing only. Never test on systems you do not have explicit written permission to assess.

Docker Engine Security Fundamentals

The Docker engine provides security through multiple layers:

Namespaces

Isolate process trees, network stacks, mount points, IPC, and UTS from the host and other containers.

Control Groups (cgroups)

Limit CPU, memory, I/O, and network bandwidth per container to prevent resource exhaustion.

Capability Dropping

Containers drop sensitive capabilities at startup. Remaining caps include: cap_chown, cap_net_bind_service, cap_setuid, etc.

Seccomp

The default Docker Seccomp profile blocks ~44 syscalls. Custom profiles can restrict further.

Default Remaining Capabilities

Secure Access to the Docker Engine

By default, Docker listens on a Unix socket at unix:///var/run/docker.sock. To enable remote access securely:
Always use HTTPS with mutual TLS for remote Docker API access. Never expose the Docker daemon over plain HTTP.

Image Security

Scanning for Vulnerabilities

Docker Content Trust (Image Signing)

Container Resource Limits

Dangerous Flags and Misconfigurations

The --privileged flag gives the container nearly all host capabilities and disables Seccomp/AppArmor:
This is the most dangerous Docker misconfiguration. Avoid it entirely in production.
If the Docker socket /var/run/docker.sock is mounted inside a container or accessible to a non-root user, full host compromise is trivial:
Using only the API (no Docker CLI):
Prevent SUID abuse inside containers:

SELinux in Docker

SELinux adds label-based mandatory access control on top of Docker’s isolation: Policy rules ensure container_t processes only interact with container_file_t objects, limiting damage from compromised containers.

DoS from a Container

Demonstrate container resource limits matter:

Secrets Management

1

Avoid Environment Variables for Secrets

Environment variables are visible via docker inspect and in process listings. Never store secrets this way.
2

Use Docker Secrets

3

BuildKit Build-Time Secrets

Advanced Container Runtimes

gVisor

A Go-based application kernel (runsc) that intercepts and handles syscalls in user space, providing strong isolation. Integrates with Docker and Kubernetes.

Kata Containers

Runs containers inside lightweight VMs using hardware virtualization as a second isolation layer. Combines container speed with VM security boundaries.

Hardening Summary

Run docker-bench-security against your Docker host to automatically audit dozens of CIS Docker Benchmark checks.
Essential hardening practices:
  • Never use --privileged or mount the Docker socket inside containers
  • Run containers as non-root users with user namespaces enabled
  • Drop all capabilities (--cap-drop=ALL) and add only required ones
  • Use --security-opt=no-new-privileges to block SUID escalation
  • Set resource limits (--memory, --cpu-shares) on all containers
  • Apply Seccomp and AppArmor profiles
  • Use official signed images only; enable Docker Content Trust
  • Regularly rebuild images to apply security patches
  • Use separate containers per microservice
  • Never put SSH inside a container; use docker exec instead

References