Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Containers, Namespaces & CGroups
OS

Containers, Namespaces & CGroups

Understand how Linux containers (Docker) achieve lightweight isolation using namespaces and cgroups.

Containers provide OS-level virtualization — multiple isolated user-space environments sharing the same kernel. Unlike VMs (which virtualize hardware), containers virtualize the OS itself.

Namespaces — What the Container Can See

Each container gets its own view of the system, isolated via Linux namespaces:

NamespaceWhat it isolatesWhy it matters
PIDProcess IDsContainer processes see only their own process tree
NetworkNetwork interfaces, IP, routingEach container has its own eth0, port space
MountMount points, filesystemContainer has its own root filesystem
UTSHostname, domain nameContainer can have its own hostname
IPCInter-process communicationSystem V IPC, POSIX message queues
UserUser and group IDsRoot inside container ≠ root outside
CgroupCgroup hierarchyResource limits visibility

When Docker runs a container, it creates new namespaces for that container. The container’s PID 1 is PID 4242 on the host — but inside the PID namespace, it sees itself as PID 1.

CGroups — What the Container Can Use

Cgroups (control groups) limit and account for resource usage:

ResourceWhat cgroup controls
CPULimit CPU share or number of cores
MemorySet hard/soft memory limits
Disk I/OThrottle read/write bandwidth
NetworkClassify and prioritize traffic
PIDsLimit total processes in the cgroup

Container vs Image

  • Image: read-only template (layered filesystem). Immutable.
  • Container: a running instance of an image — read-write layer on top of the image’s read-only layers.

Why Containers Are Lightweight

VMContainer
OS per unitFull guest OS (GB)Shared kernel (MB)
Boot timeMinutesMilliseconds
Memory overheadGB (OS + app)MB (just app)
Density per hostTensHundreds/thousands

Q: What Linux features make containers possible?

A: Namespaces (isolate what the container can see — PID, network, mount, etc.) and cgroups (limit what the container can use — CPU, memory, I/O). Together they provide lightweight isolation with a shared kernel.

Q: How is a container different from a VM?

A: A VM virtualizes hardware — each guest runs its own kernel. A container virtualizes the OS — all containers share the host kernel. Containers are smaller (MB vs GB), start faster (ms vs minutes), but have weaker isolation.

Q: What’s the difference between a container image and a container?

A: An image is an immutable, read-only template — the blueprint. A container is a running instance of an image, with a writable layer added. You can have multiple containers from the same image.

Q: Why can’t you run a Linux container on a Windows kernel (without a VM)?

A: Containers share the host kernel. A Linux container needs Linux kernel interfaces (syscalls, namespaces, cgroups). Windows has different syscalls and a different kernel architecture. You need a Linux VM to run Linux containers on Windows.

My Private Notes

Notes are auto-saved locally to this device.