Last updated: April 29, 2026
Containers are everywhere in 2026. Docker, Kubernetes, serverless platforms that are containers underneath. This module covers the security concerns specific to the container layer — separate from the Kubernetes module (Cloud Security M4) which focused on orchestration. Here: image supply chain, runtime isolation, secrets, and container escape.
What a container is (and isn’t)
A container is a Linux process with namespaces (isolated view of processes, network, filesystem, users) and cgroups (resource limits). It is not a VM. There’s no hypervisor. A container shares the host kernel.
Implication: kernel vulnerabilities compromise containers. A container escape means a process breaks out of its namespace isolation and reaches the host.
Image supply chain
Every container starts from an image. Every image has a base (Ubuntu, Alpine, Debian, scratch). Every image has layers. Supply-chain concerns:
- Base image freshness — pin to specific digest, rebuild regularly against patched bases
- Layer analysis — scan each layer for CVEs (Trivy, Grype)
- Unnecessary packages — every package is attack surface; use minimal bases
- Registry provenance — pull from trusted registries, verify signatures
- Image signing — Cosign, Notary v2 — verify provenance at deploy time
# Scan an image with Trivy
trivy image --severity CRITICAL,HIGH nginx:1.25
# Pin to digest (immutable)
FROM nginx@sha256:a1b2c3d4... (not FROM nginx:latest)
# Sign an image with Cosign
cosign sign --key cosign.key myregistry/myapp:v1
# Verify at deploy
cosign verify --key cosign.pub myregistry/myapp:v1
Dockerfile hardening
- Non-root user — add
USERdirective; never run as root inside container - Minimal base — distroless, Alpine, scratch where possible
- Multi-stage builds — compile in one stage, copy binary to clean runtime stage
- No secrets in layers — COPY / ENV don’t put secrets (they persist in image history)
- Health checks —
HEALTHCHECKdirective for runtime reliability - Read-only root filesystem —
docker run --read-only; writable tmpfs only where needed
Runtime isolation — the security boundary
Default Docker runs with significant capabilities and limited isolation. Harden every production container:
# Full hardening
docker run \
--user 1000:1000 \ # non-root
--read-only \ # rootfs read-only
--tmpfs /tmp:rw,noexec,nosuid \ # writable tmp with restrictions
--cap-drop ALL \ # drop all capabilities
--cap-add NET_BIND_SERVICE \ # add only what's needed
--security-opt no-new-privileges \ # prevent suid escalation
--security-opt seccomp=profile.json \ # system-call filter
--security-opt apparmor=docker-default \
myimage
Capabilities — the privilege lever
Linux capabilities split root’s “do anything” into granular privileges. A container without capabilities is a nearly-harmless Linux process. Drop all, add only what’s required.
- CAP_SYS_ADMIN — near-root. Required for mount, namespace manipulation. Default
--privilegedhas this. Almost never needed for apps. - CAP_NET_ADMIN — network config changes (firewall rules, routing). Needed only by network-infrastructure containers.
- CAP_NET_BIND_SERVICE — bind to ports <1024. Common legitimate need.
- CAP_CHOWN, CAP_DAC_OVERRIDE — file ownership / permission bypass. Rarely needed.
Default Docker containers have ~14 capabilities. Best practice: drop all, add required ones.
Common container escape vectors
- Running as root in container + CAP_SYS_ADMIN — attacker can unshare namespaces, mount host filesystems
- Docker socket mounted (
-v /var/run/docker.sock:/var/run/docker.sock) — attacker inside can create privileged containers on host = full host compromise - Host PID namespace sharing (
--pid=host) — attacker sees + signals host processes - Writable host-path volumes (
-v /:/host) — trivial escape via writing host files - Old runc / containerd — historical CVE-2019-5736 allowed rewriting runc binary from inside container
- Kernel vulnerabilities — Dirty Pipe, Dirty CoW, others allow escalation from container to host kernel
Secrets
Secrets in containers: never in environment variables (visible via docker inspect), never in image layers. Use:
- Docker secrets (Swarm)
- Kubernetes Secrets (base64 but encrypted at rest if configured)
- External secret stores (Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager) via CSI driver or sidecar
- Init-container pattern: fetch secret at start, write to tmpfs mount, app reads from there
Runtime detection
- Falco — syscall-based runtime rules. Detects unexpected shell spawning, network connections, filesystem access
- Tetragon (Cilium) — eBPF-based, broader policy enforcement
- Sysdig Secure — commercial, strong coverage
- Cloud-native — AWS GuardDuty Runtime Monitoring, Azure Defender for Containers, GCP Container Threat Detection
Classic Falco alerts: “Terminal spawned in container”, “Write below /etc in container”, “Outbound connection to non-allowlisted IP”.
Quick reference summary
- Container ≠ VM. Shares host kernel. Kernel CVEs = container escape risk
- Supply chain: Trivy scans, Cosign signing, pinned digests, minimal bases, curated registries
- Dockerfile: non-root USER, distroless, multi-stage, no secrets in layers
- Runtime: –read-only, –cap-drop ALL + selective cap-add, seccomp/apparmor, no-new-privileges
- Never mount Docker socket or host filesystem into untrusted containers
- Secrets: external stores + CSI/sidecar; never environment variables
- Runtime detection: Falco / Tetragon / cloud-native
Module Quiz · 20 questions
Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.
Custom team training + practitioner advisory
Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.