Container Security
& Isolation
Understand how containers package applications, how they achieve isolation, and why their security model fundamentally differs from virtual machines.
What Is a Container?
A container is a lightweight, standalone package that bundles an application with everything it needs to run: code, runtime, libraries, and configuration files. Unlike installing software directly on your computer, containers create a consistent, reproducible environment that works the same everywhere.
Key Terminology
Why Containers Matter for Security
Modern applications are built from dozens of microservices: small, independent components that each run in their own container. This architecture creates a larger attack surface, but also enables powerful security strategies.
The Shared Kernel Model
Namespaces & cgroups
Linux containers rely on two core kernel mechanisms to create isolation. Together, they define what a container can see and what resources it can use.
Virtual Machine Architecture
Containers vs. Virtual Machines
| Containers | Virtual Machines | |
|---|---|---|
| Kernel | Shared with host | Own guest kernel |
| Isolation Mechanism | Namespaces + cgroups | Hypervisor + hardware |
| Boot Time | Milliseconds | Seconds to minutes |
| Size | MBs (image layers) | GBs (full OS disk) |
| Isolation Strength | Process-level (weaker) | Hardware-level (stronger) |
| Density | Hundreds per host | Tens per host |
| Attack Surface | Shared kernel exposes risk | Smaller (hypervisor only) |
Isolation Boundaries in Depth
The Container Escape Problem
Because containers share the host kernel, a vulnerability in the kernel itself can allow an attacker to "escape" the container and gain access to the host system or other containers. This is the fundamental security limitation of containers compared to VMs.
Defense in Depth for Containers
Security Checklist: Step by Step
Example 1: Insecure vs. Secure Image
Runs as: root
Installs: curl, wget, vim, git
Filesystem: writable
Capabilities: all defaults
Runs as: appuser (UID 1001)
Installs: only app runtime
Filesystem: read-only
Capabilities: all dropped
Example 2: Network Isolation
Example 3: Privilege Escalation
This scenario shows how running a container as root with --privileged mode creates a direct path to host compromise. Compare with a hardened configuration.
2. Gets root shell inside container
3. Mounts host filesystem via /dev
4. Writes SSH key to host /root/.ssh
5. Full host access
2. Gets shell as non-root user
3. Cannot mount devices (no capability)
4. Filesystem is read-only
5. Attack contained
Common Mistakes
Summary: Isolation Landscape
| Container | VM | Bare Metal | |
|---|---|---|---|
| Isolation Level | Process | Hardware | None |
| Overhead | Very Low | Moderate | None |
| Kernel | Shared | Dedicated | Shared (one app) |
| Escape Risk | Kernel vulns | Hypervisor vulns | N/A |
| Density | High | Medium | 1 per machine |
| Best For | Microservices | Multi-tenant | Single workloads |
Question 1 of 5
What is the primary reason container isolation is considered weaker than VM isolation?
Question 2 of 5
Which two Linux kernel features are the foundation of container isolation?
Question 3 of 5
A developer runs a container with --privileged mode enabled. What security consequence does this have?
Question 4 of 5
Which practice best reduces the attack surface of a container image?
Question 5 of 5
Why do many cloud providers run containers inside virtual machines rather than directly on bare metal?