Sign in Start free

EngineeringFree course

Containers: How They Really Work

Build a container from first principles: Linux namespaces and cgroups with unshare, an OCI image assembled from tar layers and JSON, the image run with runc, overlay copy-on-write, container networking, registries, and hardening, with real outputs throughout.

  • Level Junior → Expert
  • Time 230 min
  • Modules 10
  • Exercises 17 with worked solutions
  • Includes Lab, 5-question quiz, references

What you'll learn

  • Explain containers versus virtual machines and the OCI standards
  • Isolate processes with namespaces and limit them with cgroups
  • Build, read and run an OCI image by hand
  • Explain layers, copy-on-write, networking and registries
  • Harden containers: non-root, read-only, capabilities, seccomp, limits

Each lesson is tagged Junior, Mid or Expert, so you can start where you are. Finish with the lab and the quiz; a score of 4 out of 5 marks the course complete in this browser.

The lessons below are in English for now, because they quote technical names, commands and log fields. An Arabic version is planned.

Course map

Each module moves from fundamentals to applied work to an expert challenge. Exercises have worked solutions: try first, then open the solution. 10 modules · 17 exercises · ~3.8 hours

  1. 0Start here: what a container really isJuniorMidExpert20 min · 0 exercises
  2. 1Namespaces: isolating what a process can seeJuniorMidExpert25 min · 2 exercises
  3. 2cgroups: limiting what a process can useJuniorMidExpert20 min · 2 exercises
  4. 3Images: layers, manifests and digests (OCI image format)JuniorMidExpert30 min · 2 exercises
  5. 4Runtimes: from image to running containerJuniorMidExpert30 min · 2 exercises
  6. 5Layered file systems and copy-on-writeJuniorMidExpert20 min · 2 exercises
  7. 6Container networkingJuniorMidExpert20 min · 2 exercises
  8. 7Registries and distributionJuniorMidExpert15 min · 1 exercises
  9. 8Container security: isolation and hardeningJuniorMidExpert30 min · 3 exercises
  10. 9Choosing tools, cheat sheet and assessmentJuniorMidExpert20 min · 1 exercises

No prior experience is needed. Module 0 covers the architecture, installation and configuration, and sets up the project you extend in every module. Each command is labelled with its impact (read-only, changes files, changes the system, uses the network). Work on a computer or virtual machine you control.

0

Start here: what a container really is

Goal: Separate the idea of a container from any one tool, compare containers with virtual machines, and set up the lab.

20 min

A process with a different view of the system

A container is an ordinary Linux process that the kernel has given a restricted view of the system (its own process tree, file system, hostname and network) and a resource budget. An image is the packaged file system and settings it starts from.

Containers package an application with exactly the libraries it needs, start in milliseconds, and run the same way on a laptop, a CI runner and a production cluster. Because they share the host kernel, they are much lighter than virtual machines, and that also makes their security boundary different.

Docker made containers easy, but it is only one tool. The pieces are standardised by the Open Container Initiative (OCI): an image format, a runtime specification and a distribution (registry) API. Docker, Podman, containerd, CRI-O and Kubernetes all build on them.

Virtual machinesAppAppAppLibrariesLibrariesLibrariesGuest OS + kernelGuest OS + kernelGuest OS + kernelHypervisorHost OS / hardwareContainersAppAppAppLibrariesLibrariesLibrarieskernel isolationkernel isolationkernel isolationContainer runtimeHost Linux kernel (shared)A VM virtualises hardware and boots its own kernel; a container is an isolated process group on the host kernel.
Youdocker run, podman run, kubectl applyEngine / orchestratordeveloper CLI and API, or a cluster schedulerDockerKubernetesContainer managerimages, snapshots, lifecycle, networkingcontainerdPodmanOCI runtimecreates the isolated process from a bundleruncCRI-OLinux kernelnamespaces, cgroups, capabilities, seccomp, overlayfsLinuxHardwareCPU, memory, disk, networkThe container stack from hardware to your command; each module highlights the layer it explains.
KernelLinuxLinuxUbuntuUbuntuDebianDebianRuntimeruncruncCRI-OCRI-OgVisorgVisorManagercontainerdcontainerdPodmanPodmanBuildKitBuildKitEngineDockerDockerDocker ComposeDocker ComposePortainerPortainerRegistryDocker HubDocker HubGHCRGHCRHarborHarborOrchestrateKubernetesKubernetesK3sK3sOpenShiftOpenShiftSecureTrivyTrivySyftSyftFalcoFalcoThe container ecosystem by layer.
Virtual machineContainer
Isolationhardware virtualisation, separate kernelkernel features on a shared kernel
Start timetens of secondsmilliseconds
Sizegigabytesmegabytes
Best fordifferent OSes, strong tenant isolationpackaging and running services densely

Quick check: A container image built for Linux on x86-64 runs on…

The lab and the course project

In this course you will containerise the Rimal Logistics shipment tracker (the Python API from the DevOps course) without Docker: you isolate it with namespaces, limit it with cgroups, package it as an OCI image from tar files and JSON, and run it with runc, the runtime underneath Docker and Kubernetes. Once you can do it by hand, every tool's behaviour makes sense.

Ubuntu / Debian
sudo apt install runc jq curl util-linux python3
runc --version

Commands that change kernel state need root, so they start with sudo. All outputs in this course were produced by running these exact commands.

shell · the kernel features you will use
uname -s
ls /proc/self/ns
runc --version | head -n 1
Output
Linux
cgroup
ipc
mnt
net
pid
pid_for_children
time
time_for_children
user
uts
runc version 1.5.3

Tools in this course

DockerBuild

Developer platform: CLI, engine, build, Compose, Desktop.

Use it for: building and running containers locally and in CI

Integrates with: containerd, BuildKit, registries

PodmanBuild

Daemonless, rootless-first engine with a Docker-compatible CLI; runs pods.

Use it for: Linux servers, rootless workloads, RHEL

Integrates with: systemd, Kubernetes YAML

containerdRuntime

Industry-standard container manager (CNCF): images, snapshots, lifecycle.

Use it for: the engine inside Docker and most Kubernetes nodes

Integrates with: runc, CRI, nerdctl

runcRuntime

Reference OCI runtime: creates namespaces and cgroups and starts the process.

Use it for: the last step of every docker run

Integrates with: containerd, CRI-O, Podman

KubernetesOperate

Orchestrator that schedules containers across many machines.

Use it for: running containers in production

Integrates with: containerd, CRI-O

Project step 0

Prepare the lab

Goal: Create the project folder; a setup step has copied a Python runtime from the host into base/, the equivalent of a python slim base image.

shell
cd ~/tracker-oci && ls && du -sh base base.tar | sed 's/\t/  /'
Output
base
base.tar
50M  base
49M  base.tar
1

Namespaces: isolating what a process can see

Goal: Create UTS, PID, mount and network namespaces with unshare and see exactly what each one isolates.

25 min

Free account Create a free account or sign in to continue this course.

2

cgroups: limiting what a process can use

Goal: Understand control groups, set memory and process limits, and observe the kernel enforcing them.

20 min

Free account Create a free account or sign in to continue this course.

3

Images: layers, manifests and digests (OCI image format)

Goal: Build a real OCI image by hand from two tar layers and JSON, and read every part of it.

30 min

Free account Create a free account or sign in to continue this course.

4

Runtimes: from image to running container

Goal: Unpack the image into a bundle, configure it with the OCI runtime spec, and run, inspect and stop it with runc.

30 min

Free account Create a free account or sign in to continue this course.

5

Layered file systems and copy-on-write

Goal: See how overlayfs combines read-only image layers with a writable container layer, including deletions.

20 min

Free account Create a free account or sign in to continue this course.

6

Container networking

Goal: Understand how isolated network namespaces get connectivity: veth pairs, bridges, NAT and port publishing.

20 min

Free account Create a free account or sign in to continue this course.

7

Registries and distribution

Goal: Push and pull images safely: the registry API, tags versus digests, and keeping images trustworthy.

15 min

Free account Create a free account or sign in to continue this course.

8

Container security: isolation and hardening

Goal: Understand where the container boundary really is, and apply non-root, read-only, capability, seccomp and resource controls.

30 min

Free account Create a free account or sign in to continue this course.

9

Choosing tools, cheat sheet and assessment

Goal: Choose the right engine and runtime, review the course, and prove the skills on a new service.

20 min

Free account Create a free account or sign in to continue this course.

Quick reference (the cheat-sheet lessons and the PDF content)
1

Containers versus virtual machines

Junior
Virtual machinesApp A | App B | App Ceach with its own librariesGuest OS | Guest OS | Guest OSa full kernel per VM: GBs, minutes to bootHypervisorhardware virtualizationHost hardwareContainersApp A | App B | App Ceach with its own librariesContainer runtimecontainerd, CRI-O, runcOne shared host kernelnamespaces + cgroups isolate processesHost OS and hardwareContainers are isolated processes, not small VMs: a kernel bug or a privileged container can reach the host.
2

The kernel features that make a container

Mid
FeatureWhat it isolates or limitsSee it
PID namespaceProcess IDs: PID 1 inside the containerlsns -t pid
Network namespaceInterfaces, routes, portsip netns, nsenter -t PID -n ip a
Mount namespaceFilesystem view (the image's root)findmnt -N PID
UTS, IPC namespacesHostname; shared memory and semaphoreshostname inside differs
User namespaceRoot in the container maps to an unprivileged host user/proc/PID/uid_map
cgroups v2CPU, memory, PIDs, I/O limits and accountingcat /sys/fs/cgroup/.../memory.max
CapabilitiesSplits root into ~40 privileges (NET_ADMIN, SYS_ADMIN …)capsh --print
seccomp, AppArmor, SELinuxWhich system calls and files a process may usegrep Seccomp /proc/PID/status
3

Images and layers

JuniorMid
Writable layerCreated per container, lost when the container is removedcontainerCOPY app/Your application code: changes often, keep it lastlayer 4RUN pip installDependencies: cached while requirements do not changelayer 3RUN apt-get …OS packages for the applayer 2FROM base imageDistroless, slim or Alpine base: pinned by digestlayer 1

Key facts

  • Layers are read-only and shared between images: pulls and disk are cheaper
  • An image is identified by its digest (sha256:…); a tag like :1.4 can be moved
  • Deleting a file in a later layer does not remove it from earlier layers: secrets stay in history
  • Multi-arch images: one tag, a manifest list per CPU (amd64, arm64)
4

From build to running process

JuniorMid
BuildDockerfile, buildahPushregistryPullby digestUnpacksnapshotterCreatenamespaces, cgroupsRunrunc starts PID 1
5

Who does what: the runtime stack

Mid

Kubernetes talks to containerd or CRI-O through the CRI. Docker-built images run everywhere because they follow the OCI image spec.

You or the orchestratordocker CLI / kubectlasks for a containerDocker Engine / kubeletmanages lifecycleHigh-level runtimecontainerd or CRI-Oimages, snapshots, CRI APIcontainerd-shimkeeps the container aliveLow-level runtimerunc or crunOCI runtime: sets up namespacesgVisor, Katasandboxed alternatives
6

Container lifecycle and states

JuniorMid
shell · lifecycle (Docker or nerdctl)
docker create --name web nginx:1.27   # created
docker start web                      # running
docker pause web; docker unpause web  # frozen by cgroup freezer
docker stop web       # SIGTERM, then SIGKILL after 10 s
docker rm web         # writable layer deleted
docker inspect web --format '{{.State.Status}} {{.State.ExitCode}}'
Exit codeUsually means
0Finished normally
1Application error
125The runtime command failed
126 / 127Command not executable / not found
137SIGKILL: out of memory or forced stop
143SIGTERM: stopped gracefully
7

Storage and networking basics

Junior

Storage

  • Volumes: managed by the engine, survive the container: use for data
  • Bind mounts: a host path inside the container: convenient, riskier
  • tmpfs: memory only, for secrets and scratch data
  • Never keep state in the writable layer

Networking

  • bridge (default): private network, publish ports with -p 8080:80
  • host: shares the host network stack, no isolation
  • none: no network, for batch jobs
  • Containers on the same user-defined network resolve each other by name
  • Bind published ports to 127.0.0.1 unless they must be public
8

Security boundaries in one table

MidExpert
SettingDefault riskSafer choice
Run as rootRoot in container = root on host if it escapesUSER 10001, or rootless mode / user namespaces
--privilegedAll capabilities and devices: no real isolationNever; add only the single capability needed
Writable root filesystemMalware and tampering persist in the container--read-only plus a tmpfs for /tmp
Docker socket mountedFull control of the hostDo not mount /var/run/docker.sock
Image from an unknown publisherMalware, cryptominers, old CVEsTrusted base images, pinned digest, signed
No resource limitsOne container starves the host--memory, --cpus, --pids-limit
Next step Take the Docker in Practice course to build and run images, then Kubernetes Operations to run them at scale.

Key terms

Namespace
A kernel feature that gives a process its own view of a resource: PIDs, mounts, network, hostname, users.
cgroup
A kernel group that measures and limits CPU, memory, processes and I/O.
OCI image
Layers (tar), a config and a manifest, all addressed by SHA-256 digest.
OCI runtime (runc)
Creates the isolated process from a bundle: rootfs + config.json.
OverlayFS
Read-only image layers plus a writable container layer merged into one tree.
Capability
One slice of root's power; containers should drop all they do not need.

Hands-on lab

Free account Create a free account or sign in to continue this course.

Knowledge check

Answer all five questions, then check your answers. Each answer comes with a short explanation.

1What does a container share with its host?
2Exit code 137 usually means…
3Why can a digest never point to different content?
4Where does a container's write go with OverlayFS?
5Which setting is effectively root on the host?

Further reading

Put it into practice

Use these ThreatAI tools to apply what you learned to your own environment.