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.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 atunix:///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 scan
- trivy
- snyk
- clair-scanner
Docker Content Trust (Image Signing)
Container Resource Limits
Dangerous Flags and Misconfigurations
--privileged Flag
--privileged Flag
The This is the most dangerous Docker misconfiguration. Avoid it entirely in production.
--privileged flag gives the container nearly all host capabilities and disables Seccomp/AppArmor:Writable Docker Socket
Writable Docker Socket
If the Docker socket Using only the API (no Docker CLI):
/var/run/docker.sock is mounted inside a container or accessible to a non-root user, full host compromise is trivial:no-new-privileges Security Option
no-new-privileges Security Option
Prevent SUID abuse inside containers:
Capability Management
Capability Management
SELinux in Docker
SELinux adds label-based mandatory access control on top of Docker’s isolation:| Label | Applied To |
|---|---|
container_t | Container processes (assigned by container engine) |
container_file_t | Files inside containers |
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
Avoid Environment Variables for Secrets
Environment variables are visible via
docker inspect and in process listings. Never store secrets this way.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.
- Never use
--privilegedor 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-privilegesto 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 execinstead