Use it when hardening containers or reviewing a pod's security settings.
Container Isolation and Security Defaults
Container isolation and security defaults: containers run with dropped capabilities, seccomp and AppArmor/SELinux profiles, but often as root inside. Hardening adds non-root users, read-only root filesystems, no privilege escalation and minimal capabilities.
1. docker inspect <c> --format '{{.Config.User}} {{.HostConfig.Privileged}} {{.HostConfig.CapAdd}}'.
2. Kubernetes: kubectl get pod <p> -o yaml | grep -A10 securityContext.
3. Namespace PSA labels: kubectl get ns <ns> --show-labels.
4. Fix in image/spec.
5. Re-deploy and test.
image user → runtime defaults (caps, seccomp, LSM) → pod securityContext → admission policy
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Run as a non-root user (USER in the image or --user). Add only the single capability a feature needs with --cap-add. Use --read-only and tmpfs for writable paths, and confirm the settings with docker inspect.
Step 2 Common failures Narrow the fault
Granting --privileged to fix one permission error opens the host. Mounting the Docker socket into a container gives it root on the host. Disabling the LSM profile hides the real cause of a denial.
Avoid --privileged, hostPath and host namespaces. Run as non-root (USER, runAsNonRoot), drop all capabilities and add back only needed ones, set allowPrivilegeEscalation: false and readOnlyRootFilesystem. Enforce with Pod Security Admission (restricted).
docker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
ReferenceWhat it is1 section · depth on demand
How it works
A container starts as root inside its user namespace unless a user is set. Capabilities split root powers into small units; the runtime keeps a minimal set. Seccomp filters syscalls; AppArmor or SELinux limit file and network access. Rootless runtimes add a user namespace so container root maps to an unprivileged host user.
ReferenceImportant terms & boundaries3 sections · depth on demand
Default protections and how to tighten
| Mechanism | Default | Tighten with |
|---|---|---|
| Namespaces (pid, net, mnt, uts, ipc) | On | --userns / user namespaces |
| cgroups (CPU, memory, pids) | No limits | --memory, --cpus, --pids-limit |
| Capabilities | Reduced set | --cap-drop ALL --cap-add <needed> |
| Seccomp | Default profile | Custom profile |
| AppArmor/SELinux | Default profile | Custom profile |
| Root filesystem | Writable | --read-only + tmpfs |
| User | root | USER 10001 in Dockerfile |
Never use --privileged, the host network/PID namespace or the Docker socket mount for untrusted workloads.
In depth
Container isolation is layered. Each layer covers a different attack path, and removing one is not compensated by the others.
| Layer | Default in Docker/containerd | What it stops |
|---|---|---|
| Namespaces | pid, net, mnt, uts, ipc | Seeing and signalling host processes, host network |
| Capabilities | Reduced set (no SYS_ADMIN, NET_ADMIN, SYS_MODULE …) | Mounting filesystems, loading modules, changing host network |
| Seccomp | Default profile blocks around 40+ syscalls | Rare, dangerous syscalls such as kexec_load, open_by_handle_at |
| AppArmor / SELinux | docker-default profile or container_t type | Writing to host paths outside the container |
| No new privileges | Off by default; --security-opt no-new-privileges | setuid binaries gaining privileges |
| User namespace | Off by default | Root in the container being root on the host |
What --privileged actually does
It grants all capabilities, disables seccomp and the LSM profile, and exposes host devices. Treat it as running the process on the host.
Worked check — what does this container really have?
docker inspect -f '{{.HostConfig.Privileged}} {{.HostConfig.CapAdd}} {{.HostConfig.SecurityOpt}}' web
docker exec web grep -E 'CapEff|NoNewPrivs|Seccomp' /proc/1/status
# CapEff: 00000000a80425fb Seccomp: 2 (filter active) NoNewPrivs: 1
capsh --decode=<CapEff> turns the mask into capability names. Seccomp: 0 means no filter is active.
Practical hardening order
Non-root user → drop all capabilities and add back only what is needed → read-only root filesystem with tmpfs for scratch paths → no-new-privileges → never mount the Docker or containerd socket into a workload.
Common mistakes
- Running as root and with
--privileged.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.