Containers and Docker, hands on
Namespaces, cgroups and image layers explained step by step — with a quiz.
Containers and Docker, hands on
What really happens when you type docker run.
docker pull ubuntu:22.04 downloads read-only layers (base files) from a registry.
docker run asks the kernel for new PID, mount, network, UTS, IPC and user namespaces — the container gets its own view of processes, files and network.
A control group is created; flags such as --memory=256m --cpus=0.5 become cgroup limits enforced by the scheduler and memory manager.
The image layers are stacked with a writable layer on top (copy-on-write). Deleting the container discards only that layer.
The command (e.g. bash) starts as PID 1 inside its namespace — but on the host it is an ordinary process with a normal PID, visible with ps.
$ docker run -d --name web nginx
$ docker exec web ps -e | head -3 # inside: nginx is PID 1
PID TTY TIME CMD
1 ? 00:00:00 nginx
$ ps -e | grep nginx | head -1 # on the host: a normal PID
23817 ? 00:00:00 nginxWhich kernel feature hides other containers' processes?
Which feature stops a container from using all the RAM?
Containers start faster than VMs mainly because…