Day 239: Containers - Processes with Isolation and Resource Control
A container is not a mini-VM. It is still a set of ordinary processes running on the host kernel, but wrapped in kernel mechanisms that change what those processes can see and how much of the machine they can consume.
Today's "Aha!" Moment
Containers are often introduced through tooling:
docker run- images
- registries
- orchestration
That helps people use them, but it often hides what they actually are.
The aha is:
- a container is fundamentally a process-level isolation story, not a hardware virtualization story
Inside a container, the process may feel like it has:
- its own PID space
- its own filesystem view
- its own network interfaces
- its own hostname
But those are controlled views, not a separate kernel.
The host kernel is still shared.
This is why two kernel features matter so much:
- namespaces decide what the process can see
- cgroups decide how much of the machine the process can use
Once we see that, containers stop being mysterious. They become a composition of familiar process and kernel ideas from earlier lessons.
Why This Matters
Imagine we want to run several services on the same machine:
- an API
- a background worker
- a cache
- an internal admin tool
We want each one to feel self-contained, with:
- its own dependencies
- limited blast radius
- bounded CPU and memory usage
- predictable packaging
A naive process model gives us execution, but not enough isolation of view or enough control of resource limits.
A full virtual machine gives stronger isolation, but with more overhead and another guest kernel to manage.
Containers sit in the middle:
- lighter than VMs
- more isolated and manageable than naked processes
This matters operationally because it affects:
- density on a host
- packaging and deployment
- failure isolation
- security boundaries
- performance assumptions
If we misunderstand the mechanism, we make bad decisions such as:
- assuming a container has its own kernel
- assuming container isolation is equivalent to VM isolation
- ignoring cgroup limits and then being surprised by CPU throttling or OOM kills
Learning Objectives
By the end of this session, you will be able to:
- Explain what a container really is - Describe it as a set of host-kernel processes with isolation and resource controls layered on top.
- Differentiate namespaces from cgroups - Show what each one contributes to the container illusion.
- Evaluate the trade-off - Recognize when container isolation is sufficient and when the stronger boundary of a VM is more appropriate.
Core Concepts Explained
Concept 1: Namespaces Change What a Process Can See
Namespaces are about view and identity.
They let a process see a scoped version of parts of the system, such as:
- process IDs
- mount points
- network interfaces
- hostname/domain name
- IPC resources
- user/group mappings
That is why a process inside a container can believe:
- "I am PID 1"
- "this is the whole filesystem I know"
- "these are the network devices I have"
even though the host machine has far more processes, mounts, and devices outside that namespace.
ASCII sketch:
host kernel
many processes
many mounts
many networks
containerized process view
own PID namespace
own mount namespace
own network namespace
The key idea is:
- namespaces change visibility, not the fact of sharing one kernel
That is what gives containers their "feels like its own machine" effect.
Concept 2: cgroups Change How Much Resource a Process Family Can Consume
If namespaces answer "what can I see?", cgroups answer:
- "how much can I take?"
Control groups let the kernel account for and limit resources like:
- CPU time
- memory
- I/O bandwidth
- number of processes
This is crucial because packaging several services onto one host is useless if one noisy workload can starve the others.
Examples:
- cap a worker pool to a fraction of CPU
- limit memory so a runaway service is OOM-killed inside its cgroup instead of wrecking the whole host
- restrict process count to stop fork storms
That means cgroups are the operational half of containers:
- without them, namespaces would provide isolation of view
- but not meaningful resource governance
So the common container illusion is really built from both pieces together:
namespaces -> "this is my world"
cgroups -> "this is my budget"
Concept 3: Containers Are Lighter Than VMs Because They Share the Host Kernel
This is the most important trade-off in the whole lesson.
A virtual machine typically gives each guest:
- its own virtualized hardware environment
- its own guest kernel
A container does not.
It shares the host kernel and isolates processes using kernel features.
That is why containers often have:
- lower startup cost
- lower memory overhead
- higher density on one machine
But it is also why they have:
- a weaker isolation boundary than a full VM
- tighter dependence on host-kernel behavior
- security implications if kernel escape or misconfiguration occurs
So the right mental model is not:
- containers are "tiny VMs"
It is:
- containers are a very efficient process-isolation packaging model built on one shared kernel
That makes them excellent for many platform and deployment workflows, but not automatically the right answer for every security or tenancy boundary.
Troubleshooting
Issue: "A container has its own kernel."
Why it happens / is confusing: The filesystem and process view can feel like a separate machine.
Clarification / Fix: Containers share the host kernel. Namespaces and cgroups change visibility and control, but they do not create a separate guest kernel the way a VM does.
Issue: "If it runs in a container, it cannot hurt the host much."
Why it happens / is confusing: Isolation language sounds stronger than it is.
Clarification / Fix: Containers reduce blast radius, but they are not equivalent to VM isolation. Misconfigurations, kernel bugs, or privileged container setups can still create serious host risk.
Issue: "Resource limits are just optional tuning."
Why it happens / is confusing: Teams focus on images and packaging first.
Clarification / Fix: cgroup limits are part of the runtime behavior of the service. CPU throttling, memory pressure, and OOM kills are not side notes; they shape how the container behaves in production.
Advanced Connections
Connection 1: Containers <-> Processes & Threads
The parallel: Containers do not replace processes; they package and isolate them. The execution model is still processes and threads on the host kernel.
Connection 2: Containers <-> Virtualization
The parallel: Containers and VMs both create useful boundaries, but they do so at different layers. Containers isolate process views on one kernel; virtualization isolates guest systems with their own kernels.
Resources
- [DOC] Linux namespaces(7)
- [DOC] Linux cgroups(7)
- [DOC] Docker: What is a Container?
- [DOC] Open Container Initiative Runtime Spec
- [BOOK] Operating Systems: Three Easy Pieces
Key Insights
- Containers are still processes on the host kernel - They feel separate because visibility and resource usage are constrained, not because they become miniature machines.
- Namespaces and cgroups do different jobs - Namespaces scope what a process can see; cgroups constrain what it can consume.
- The shared-kernel model is both the win and the risk - It gives excellent efficiency and density, but it is a weaker isolation boundary than full virtualization.
Knowledge Check
-
What is the most accurate description of a container?
- A) A full virtual machine with a guest kernel
- B) A set of host-kernel processes isolated by mechanisms such as namespaces and cgroups
- C) A special kind of programming language runtime
-
What is the main role of namespaces in containers?
- A) To define what resources a process can see as its local environment
- B) To encrypt files inside the image
- C) To remove the need for a scheduler
-
Why are containers typically lighter than VMs?
- A) Because they share the host kernel instead of booting a separate guest kernel per workload
- B) Because they do not use memory
- C) Because they only run one process
Answers
1. B: A container is best understood as host-kernel processes wrapped with isolation and resource controls.
2. A: Namespaces scope the process view of things like PIDs, mounts, and networking.
3. A: Containers avoid the overhead of a separate guest kernel, which is a major reason they start faster and pack more densely than VMs.