What is a container?

An introduction to operating-system-level virtualisation, resources and how containers work.

Docker logo

A container is an operating-system-level virtualisation technique that isolates a process or group of processes, giving them a “complete” execution context. An execution context is the set of resources (PIDs, networking, sockets, mount points…) relevant to the process.

Comparison of virtual machines and containers

Sitting between chroot and solutions such as KVM, a container avoids the cost of virtualising hardware or the operating system kernel while offering much greater control and isolation than chroot.

A container is provisioned faster than a VM and does not need to boot device emulation or an operating-system kernel, at the cost of a much lower level of isolation: processes in different containers share the same kernel.

What follows is an introduction to the general idea of containers.

1. Processes, the kernel and resources

The Linux kernel’s fundamental purpose is to mediate between programs running on a machine (processes) and the physical and virtual devices that make it up. To do so, it creates a fundamental abstraction: the resource.

Resources can have limited availability, restricted access and exclusive use. The kernel must prevent them from being monopolised, accessed improperly or used simultaneously when they are exclusive.

Communication with computer components

The kernel also performs important abstraction work: it hides the operating details of different devices and gives processes clean, unified interfaces that standardise the use of hardware from different vendors.

We can therefore conclude that processes do not “see” the devices that make up the machine they run on, but rather the representation of them provided by the kernel.

A process’s resources

The set of resources a process interacts with, and that are relevant to it, make up its execution context. In a traditional operating system, that context is unique: all processes share and see the same OS environment.

Resources shared by several processes

For example, a PID is unique to a machine, as are a semaphore or a network resource. Regardless of access rights, resources on a machine are global and, in principle, visible to all processes running on it.

2. Platform virtualisation

Platform virtualisation techniques such as KVM simulate a machine in software, sometimes with special emulation hardware such as Intel VT-x. They fully replicate the machine: devices are abstracted, a kernel is booted and, on top of it all, user processes are finally started.

Server virtualisation on a machine

3. Containers

Containers take a different approach: instead of virtualising the machine, they virtualise the process’s execution context, that is, the resources the system exposes to it and with which it interacts. The context is no longer unique within a machine, so several processes can have the same PID (provided they are in different contexts); each process in a container can have its own IPC or mount its own filesystems.

A container focuses on isolating the process and avoids the cost of virtualising devices or the kernel, which are irrelevant to the process because the OS kernel already abstracts them.

The two technological foundations of containers are cgroups and namespaces. Both technologies are built into the kernel. We introduce them in the next article: Linux namespaces.