SkillSprout
Chapter 1 · Lesson 2
Beginner
2 min read

How Containers Isolate Processes

Overview

A container can look like a small computer, but it is not always a separate operating system. It is usually a normal process on the Linux host with isolation rules around it. Docker uses Linux features called namespaces and control groups (cgroups) to create that isolation.

Detailed Notes

What the container sees

A namespace changes how a process sees a part of the host.

NamespaceWhat it isolates
Process (PID)Processes visible inside the container
NetworkInterfaces, IP addresses, routes and ports
MountFilesystem mounts
UserUser and group IDs
IPCShared-memory communication
UTSHostname

Inside a container, /bin/sh is not necessarily running on a separate kernel. Docker starts a process, and Linux namespaces decide which processes, files, network interfaces and hostnames that process can see.

Why resource limits exist

A namespace creates visibility boundaries, but it does not automatically limit resource consumption. One container could consume all available CPU or memory without cgroups.

bash
docker run --memory 256m --cpus 0.5 nginx:alpine
  • --memory 256m: the container should not use more than 256 MB of memory.
  • --cpus 0.5: the container receives at most half of one CPU over a scheduling period.

An application that exceeds its memory limit can be killed by the operating system. That is different from a program reporting an application-level out-of-memory error.

Container isolation has boundaries

Containers share the host kernel. Do not treat a container as a complete security boundary. Secure the Docker daemon, use least privileges, keep the host patched and never expose the Docker socket to an untrusted container.

Namespaces and cgroups
Architecture
ContainerProcessview limited b…PID, Mount,Networkisolated viewsCPU and Memorybounded usagenamespace rulescgroup limits
Key point. A container starts as a host process.

Namespaces control what a process can see; cgroups control how much it can use.

Common Interview Questions

Finished this lesson?

0 of 27 lessons done · 0% of the course