Sub topic 4
Containers: isolated processes, not small computers
This chapter assumes you can use a Linux or macOS shell and know what a process and a kernel are. It also assumes Docker is installed. Namespaces, cgroups, and image layers get their own chapters, so here you only need the overall model.
The working model
A container is an ordinary process, or a group of processes, that the host kernel runs with two restrictions. The kernel limits what the process can see, and it limits how much of the machine the process can use. A container does not boot an operating system and has no virtual hardware. It is not a small computer.
Think of it as a process with a restricted view of the system. Inside the container, the application sees its own process list, its own hostname, its own network interfaces, and its own root filesystem. From the host, it is one more entry in the process table.
Seeing it for yourself
On a Linux host, compare the kernel release reported by the host and by a container:
uname -r
docker run --rm alpine uname -rBoth commands print the same value. The Alpine image contains a minimal userland, meaning shell tools and libraries, but no kernel. The uname call inside the container asks the host kernel.
You can also see that the container is just a process. Start one and look for it from the host:
docker run -d --name sleeper alpine sleep 300
ps aux | grep "[s]leep 300"
docker rm -f sleeperThe sleep 300 process shows up in the host's process list. Inside the container it is PID 1, but the host assigns it a different, larger PID. The same process has two identities because each PID namespace numbers processes independently.
What the restrictions look like
The kernel provides the isolation through features you will meet in later chapters:
| Question | Kernel feature | Effect |
|---|---|---|
| What can the process see? | Namespaces | Separate process list, hostname, network, mounts |
| How much can it use? | Control groups (cgroups) | Caps on memory, CPU, and more |
| What files does it start with? | Image layers | A prepared root filesystem |
You can try the first row without Docker. This command starts a shell in new UTS and PID namespaces on Linux:
sudo unshare --uts --pid --fork --mount-proc sh -c 'hostname demo; hostname; ps aux'The hostname change applies only inside the new namespace, and ps lists only the processes in it. Docker and other container tools do this same kind of setup for you, with more namespaces and limits added.
Common errors in the mental model
- "A container is a lightweight VM." There is no guest kernel. A container cannot run a different kernel than the host, so a Linux container image cannot natively run on a Windows kernel.
- "Stopping the main process leaves the container running." The container exists because its main process exists. When PID 1 exits, the container stops.
- "A container has no resource limits by default." This is partly true. Without flags, Docker sets no memory or CPU cap, so one container can use as much as the host allows. Set limits explicitly.
- "Files inside are invisible to the host." The host kernel can see everything. Isolation limits what the container sees, not what the host sees.
Exercise
You run uname -r on a Linux host and docker run --rm alpine uname -r. The outputs match. What does this tell you about containers, and why would a VM give a different result if its guest ran another kernel version?
Show answer
The container uses the host kernel, since the Alpine image ships no kernel of its own. A VM boots its own guest kernel on virtual hardware, so uname -r inside it reports the guest kernel's release, which can differ from the host's.
Exercise
A teammate says, "I'll stop the container's operating system and keep the app running." Why does this request not make sense for a container?
Show answer
A container has no operating system of its own to stop. It is a process (or group of processes) on the host kernel. When its main process exits, the container stops.