Full lab · 13 missions · about 90 minutes
Docker: the full lab¶
In the video, I put a small status page app in a container by hand, on a Linux server with no Docker: 28 commands. Then Docker does it with a five-line recipe and two commands, and we open its container to compare. Here, you do all of it yourself, on a server of your own.
Short on time? Start with the 10-minute exercise: the Docker half on your own computer, with no VM.
The thirteen missions
- One process on one server, 4 minutes
- A folder with nothing else, 6 minutes
- Inside its own tree, 6 minutes
- Its own process list, 6 minutes
- Its own network, 7 minutes
- A limit, 7 minutes
- Not root, 5 minutes
- One folder, clean every time, 8 minutes
- Pack it: the image, 8 minutes
- One command, 5 minutes
- Stop it, remove it, keep the data, 6 minutes
- Open it: the same parts, 6 minutes
- What Docker adds, 6 minutes
The card from the video: the row each mission builds by hand
missions 2, 3 and 8
mission 4
mission 5
mission 6
mission 7
Before you start¶
You need a Linux server with Ubuntu 26.04 and no Docker on it, where you can use sudo. Use a fresh one: the lab changes it as root. A free VM from Multipass, Canonical's tool that makes Ubuntu VMs on macOS, Windows and Linux, is just right. Install it, then on your computer:
Now open a second terminal on your computer, and run multipass shell server-1 there too. The missions call them terminal 1 and terminal 2: terminal 1 runs the app, terminal 2 everything else. The prompt in both is ubuntu@server-1:~$, as in the video.
In terminal 2, get the lab from my tutorials repository on GitHub, and put the app where the video has it, in /app, with an empty /data for its log:
git clone --depth 1 --branch 284-docker-explained https://github.com/antonputra/tutorials.git
cd tutorials/lessons/284/lab
sudo mkdir -p /app /data
sudo cp app/status.py app/message.txt /app/
sudo chown $USER /data
- The app is two files:
status.py, a status page in Python, andmessage.txt, the text on the page. On each request, it reads the message, adds a line to/data/requests.logand sends the message back. - Run each command in terminal 2, unless a step says terminal 1. Run terminal 2's commands from the lab's folder, where
git cloneandcdput you. - Paste each block whole, with its copy button, and press Enter. If the lines after a
sudoline don't run, paste them one at a time. P=$(pgrep -n -f '^python3 /app/status')keeps the app's process number inP, for the next commands. Read it again each time the app starts.- Your process numbers, addresses, interface names, times and sizes will differ from the ones on this page. Mine come from a Mac with Apple silicon, so the server is arm64; on an x86_64 server, the libraries' folder is
x86_64-linux-gnu, and the loader is/lib64/ld-linux-x86-64.so.2, so your folder haslib64where mine haslib.
Mission 1. One process on one server¶
4 minutes
You start the app as a plain process, ask for its page, and see how much of the server it gets: the card's five rows.
-
In terminal 1, start the app:
It stays there, listening on 127.0.0.1, port 8000, and prints a line for each request.
-
In terminal 2, ask for the page, then look at the log:
The client's address is
127.0.0.1: the machine itself. -
The app is a process. See its number, its user and its memory:
RSSis its memory in kilobytes: about 22 MB. -
Now the card, row by row. Files: every folder in the server's root folder. Processes: every process on the server. Network: the server's own, where the app took port 8000:
-
Memory and CPU: all of the server's. User: you,
ubuntu, number 1000: -
Is Docker here? Not yet:
You get
Command 'docker' not found, with a hint how to install it. Don't install it: Docker comes in mission 9. -
Stop the app:
In terminal 1, it ends, and the prompt comes back.
Why. The app is two small files, but as a plain process it sees every folder, every process and the whole network of the server, and it can use all of its memory and CPU. One bug in the app, or one attacker getting in, and far too much of the server is in reach. The next missions take that away, one row at a time.
Mission 2. A folder with nothing else¶
6 minutes
You give the app a folder of its own as its root folder, and add files to it until it runs.
-
Make the folder, with our two files and an empty
datafolder: -
In terminal 1, start the app with this folder as its root folder:
chrootchanges the root folder. Our folder has no Python. -
Copy Python in. It's one file:
-
In terminal 1, try again. You get the same error:
Python is in the folder now. The error only names the program Linux tried to start: a different file is missing.
-
See what Python needs, and copy all of it:
ldd /usr/bin/python3.14 for f in $(ldd /usr/bin/python3.14 | grep -o '/[^ ]*'); do sudo mkdir -p /srv/status-files$(dirname $f) && sudo cp -L $f /srv/status-files$f; donelinux-vdso.so.1 (0x0000f8ce07b9c000) libm.so.6 => /usr/lib/aarch64-linux-gnu/libm.so.6 (0x0000f8ce07a90000) libz.so.1 => /usr/lib/aarch64-linux-gnu/libz.so.1 (0x0000f8ce07a50000) libexpat.so.1 => /usr/lib/aarch64-linux-gnu/libexpat.so.1 (0x0000f8ce07a00000) libc.so.6 => /usr/lib/aarch64-linux-gnu/libc.so.6 (0x0000f8ce07830000) /lib/ld-linux-aarch64.so.1 (0x0000f8ce07b60000)Four libraries, and the loader, the small program that brings them in. The first line isn't a file. The loop copies each file that
lddnames to the same place in our folder. -
In terminal 1, try again:
... Fatal Python error: Failed to import encodings module Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings' ...Python starts, and stops right away: a big part of Python is its own code, in plain files.
-
Copy Python's own code in:
-
In terminal 1, start the app once more. No error: it stays there, and runs.
-
Ask for the page, and count what it took:
Why. Our code is plain text, and Python runs it. Python needs its libraries, the loader that brings them in, and its own code, and Linux looks for each one in the root folder. So an app is its code and a lot more: over a thousand files and 42 MB, for two small files of our own. It needs a folder like ours on every server it runs on.
Mission 3. Inside its own tree¶
6 minutes
You look around from inside the folder, and see what the app can still reach.
-
For the app, the tree of files begins at our folder:
When the app opens
/app/message.txt, the kernel opens/srv/status-files/app/message.txt. Same name, same system call, new result. -
Look around from inside.
lsis a program too, and our folder doesn't have it: -
Add one small file of basic commands, BusyBox, and look again:
sudo mkdir -p /srv/status-files/bin /srv/status-files/proc sudo cp /usr/bin/busybox /srv/status-files/bin/ sudo chroot /srv/status-files /bin/busybox --install -s /bin sudo chroot /srv/status-files ls /Six folders, not the server's 22. The server's own files are out of reach:
-
Your request from mission 2 went into the app's own
datafolder. If we throw the folder away, the log goes with it. So we make a folder we keep, outside, and mount it at the app's/data:sudo ls -l /srv/status-files/data sudo rm /srv/status-files/data/requests.log sudo mkdir /srv/status-keep sudo mount --bind /srv/status-keep /srv/status-files/data findmnt -o TARGET,SOURCE /srv/status-files/datatotal 4 -rw-r--r-- 1 root root 43 Nov 18 12:03 requests.log TARGET SOURCE /srv/status-files/data /dev/sda1[/srv/status-keep]The new log line is in the folder we keep.
-
The app still runs as root, with all of root's powers, and with
/procin its folder it would see every process on the server: -
From inside, root can even stop one of your own programs. Start one that only waits, and end it from inside the folder:
pgrepfinds nosleep: it's gone. Your shell saysTerminatedfor it too.
Why. chroot changes only where the app's tree of files begins. It's the same app, as root, sharing everything else with the server: its processes, its network, its memory. So the next missions add one wall at a time. The folder we keep is a bind mount: one folder shown in a second place, so the log lives outside the app's files.
Mission 4. Its own process list¶
6 minutes
You start the app with its own list of processes, a PID namespace, where it is process 1.
-
Stop the app, the usual way:
-
In terminal 1, start it in new namespaces:
unsharestarts a program in new namespaces:--pidgives it its own list of processes, and--mount-procits own/procto read it from.--rootdoes whatchrootdid. -
Ask for the page, and compare the two lists:
curl http://127.0.0.1:8000/status P=$(pgrep -n -f '^python3 /app/status') ps -o pid,user,args -p $P sudo nsenter --target $P --all --root ps grep NSpid /proc/$P/statusPID USER COMMAND 13793 root python3 /app/status.py PID USER COMMAND 1 0 python3 /app/status.py 2 0 ps NSpid: 13793 1nsenterruns a command inside the app's namespaces, sopssees its list: our app is process 1, andpsitself is 2. On the server, the same process is 13793. The app has two numbers. -
From inside, a process on the server is now out of reach:
sleep 600 & sudo nsenter --target $P --all --root kill $(pgrep -n -x sleep) pgrep -a -x sleep kill $(pgrep -n -x sleep)The shell numbers the background
sleepas job[1]. Inside, there's no process 14190. The lastkillends it from the server, and the shell says[1]+ Terminated, sometimes only after your next command. -
Try to stop the app with a plain
kill, from inside and from the server:It's still running. Process 1 of a namespace gets only the signals it asked for, and our app never asked for this one.
-
The app still shares the server's network. A second copy can't start, because port 8000 is taken:
-
Stop the app for good. Sent from the server,
KILLalways works, even on process 1:
Why. A namespace changes what a process can see. In its own PID namespace, the app sees only itself, and the kernel keeps a second number for it there. Process 1 is special in Linux: it ignores a signal unless it asked for it. Docker's containers have the same trap, as you'll see in mission 11.
Mission 5. Its own network¶
7 minutes
You give the app a network of its own, a network namespace, and connect it to the server with a cable: a pair of virtual interfaces.
-
Make a network namespace. It has one interface, and it's down:
-
In terminal 1, start the app in it:
-
The server can't reach it anymore:
-
Make the cable, a pair of virtual interfaces, and move one end into the app's network:
-
Give each end an address, and turn them on:
-
The cable works, but the page still doesn't:
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.019 ms --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.019/0.019/0.019/0.000 ms curl: (7) Failed to connect to 10.0.0.2 port 8000 after 0 ms: Could not connect to server State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 5 127.0.0.1:8000 0.0.0.0:*The app listens only on
127.0.0.1, its own network's machine-itself address, and our request comes in on10.0.0.2. -
Stop the app:
-
In terminal 1, start it again, listening on every address of its network:
-
Ask for the page at the app's address, and look at the log:
HTTP/1.0 200 OK Server: BaseHTTP/0.6 Python/3.14.4 ... <!doctype html><title>Status</title><h1>Status: OK</h1> 2026-11-18T12:03:49Z 10.0.0.1 GET /statusThe client is
10.0.0.1now: the server, at its end of the cable. -
The app has three namespaces of its own now,
mnt,netandpid. The rest it still shares with the server:
Why. A network namespace starts with nothing in it, not even a working lo. The veth pair is two interfaces joined like a cable: what goes in one end comes out of the other. 10.0.0.x is a range kept for private networks, so these addresses can't clash with the internet.
Extra: two apps, one port¶
Open terminal 3 on your computer (multipass shell server-1), and start a second copy there, in the server's own network. In terminal 3:
Then in terminal 2, both answer on port 8000, each in its own network:
curl http://127.0.0.1:8000/status
curl http://10.0.0.2:8000/status
sudo ss -ltn | grep 8000
sudo ip netns exec status ss -ltn | grep 8000
sudo kill -KILL $(pgrep -n -f '^python3 /app/status')
The last command stops the second copy, the newest.
Mission 6. A limit¶
7 minutes
You turn on the app's memory leak, and put the app in a control group that limits its memory and CPU.
-
Stop the app, and make a control group: a folder, which Linux fills with files right away:
sudo kill -KILL $P sudo mkdir /sys/fs/cgroup/status ls /sys/fs/cgroup/status | wc -l cat /sys/fs/cgroup/status/memory.maxmaxmeans no limit, yet. -
In terminal 1, start the app in the group, with its leak on, 10 MB more on every request:
sudo sh -c 'echo $$ > /sys/fs/cgroup/status/cgroup.procs && exec ip netns exec status unshare --pid --fork --mount-proc --root=/srv/status-files python3 /app/status.py --listen 0.0.0.0 --leak-mb 10'The small shell writes its own process number,
$$, into the group'scgroup.procs, andexecturns it into the start command. So the app starts in the group. -
Send eight requests, and read the group's memory meter after each one:
for i in 1 2 3 4 5 6 7 8; do curl -s -o /dev/null -w "request $i: HTTP %{http_code}, " -m 5 http://10.0.0.2:8000/status; echo "memory.current $(cat /sys/fs/cgroup/status/memory.current)"; donerequest 1: HTTP 200, memory.current 24506368 request 2: HTTP 200, memory.current 34992128 ... request 8: HTTP 200, memory.current 97898496Eight answers, and almost 100 MB. Only the server's memory would stop it.
-
Stop it, and set a limit of 64 MB:
-
In terminal 1, start the same app again, the leak still on:
-
The same eight requests:
for i in 1 2 3 4 5 6 7 8; do curl -s -o /dev/null -w "request $i: HTTP %{http_code}, " -m 5 http://10.0.0.2:8000/status; echo "memory.current $(cat /sys/fs/cgroup/status/memory.current)"; donerequest 1: HTTP 200, memory.current 23695360 ... request 5: HTTP 200, memory.current 65638400 request 6: HTTP 000, memory.current 348160 request 7: HTTP 000, memory.current 348160 request 8: HTTP 000, memory.current 24576Request 6 gets no answer. In terminal 1, the app is gone.
-
Linux killed it. The group counts it, and the kernel's log names it:
grep oom_kill /sys/fs/cgroup/status/memory.events sudo dmesg | grep "Memory cgroup out of memory" free -moom_kill 1 [ 212.911752] Memory cgroup out of memory: Killed process 17369 (python3) total-vm:85660kB, anon-rss:65100kB, ...OOM is short for out of memory.
free -mshows that most of the server's memory is still free: a limit isn't a reservation. -
The same group limits CPU time. Run a small busy program in the group, before and after a limit of 50 ms in every 100 ms, and compare the times it was paused:
time sudo sh -c 'echo $$ > /sys/fs/cgroup/status/cgroup.procs && exec python3 -c "sum(range(200000000))"' grep nr_throttled /sys/fs/cgroup/status/cpu.stat echo "50000 100000" | sudo tee /sys/fs/cgroup/status/cpu.max time sudo sh -c 'echo $$ > /sys/fs/cgroup/status/cgroup.procs && exec python3 -c "sum(range(200000000))"' grep nr_throttled /sys/fs/cgroup/status/cpu.statreal 0m0.817s user 0m0.813s sys 0m0.001s nr_throttled 0 50000 100000 real 0m2.153s user 0m0.859s sys 0m0.001s nr_throttled 17Without the limit, Linux paused it 0 times. With it, 17 times on my server, as in the video; your count depends on your CPU's speed. Either way, the same work took longer: compare the two
reallines. -
In terminal 1, start the app in the group, without the leak:
sudo sh -c 'echo $$ > /sys/fs/cgroup/status/cgroup.procs && exec ip netns exec status unshare --pid --fork --mount-proc --root=/srv/status-files python3 /app/status.py --listen 0.0.0.0'About 12 MB, well under the limit.
Why. A namespace changes how much a process sees, not how much it uses. A control group, cgroup for short, is a group of processes measured and limited as a unit, and Linux shows each one as a folder. Every process the app starts joins its group too. The CPU limit is a time budget on the shared CPUs: at most 50 ms in every 100 ms, half a CPU, and when the group has used it, Linux pauses it until the next 100 ms begins.
Mission 7. Not root¶
5 minutes
You see what root inside can do, and start the app as a user of its own.
-
The app still runs as root, and root inside shares too much. Rename the server from inside, then put the name back:
P=$(pgrep -n -f '^python3 /app/status') grep -E '^(Uid|CapEff)' /proc/$P/status hostname sudo nsenter --target $P --all --root hostname broken hostname sudo hostname $(cat /etc/hostname) hostnameThe server's name isn't in the app's namespaces, so root inside changed it for the whole server. The name in
/etc/hostnamestayed, so we put it back from there. -
Stop the app, and make a user for it, number 10001, with no home and no shell:
-
In terminal 1, start the app as that user:
-
It has none of root's powers now, so it can't rename the server:
-
But the page breaks:
In terminal 1, the app says why:
PermissionError: [Errno 13] Permission denied: '/data/requests.log'. The log belongs to root. -
Give the folder we keep to the app's user, and ask again:
Why. Root's powers are split into capabilities, and CapEff shows the ones a process can use: all ones for root, all zeros for our user. A user that owns nothing on the server can't break anything on it, but it must own what the app writes. That's the price, and Docker images pay it too: a USER line, and a /data that belongs to that user.
Mission 8. One folder, clean every time¶
8 minutes
You change a file inside, see the change stay, and fix that with stacked folders: an overlay.
-
Change the message from inside, as root:
-
In terminal 1, start the app again, the same way:
-
The change is still there, because it was made in our own files:
-
Stop the app, and stack the folders: our files at the bottom, an empty folder on top, and one merged folder for the app. Then mount the folder we keep at the merged folder's
/data:sudo kill -KILL $(pgrep -n -f '^python3 /app/status') sudo umount /srv/status-files/data sudo mkdir -p /srv/status-1/top /srv/status-1/work /srv/status-1/merged sudo mount -t overlay overlay -o lowerdir=/srv/status-files,upperdir=/srv/status-1/top,workdir=/srv/status-1/work /srv/status-1/merged sudo mount --bind /srv/status-keep /srv/status-1/merged/data findmnt -t overlay -o TARGET,FSTYPE,OPTIONS ls /srv/status-1/mergedTARGET FSTYPE OPTIONS /srv/status-1/merged overlay rw,relatime,lowerdir=/srv/status-files,upperdir=/srv/status-1/top,workdir=/srv/status-1/work,uuid=on,nouserxattr app bin data lib proc usrlowerdiris the bottom,upperdirthe top.workdiris scratch space the kernel needs. -
In terminal 1, start the app with the merged folder as its root folder. This is the 28th command of the video:
-
Make the same change. This time it lands in the top folder, and our files stay as they were:
-
Throw the top folder away, and stack a clean one:
sudo kill -KILL $P sudo umount /srv/status-1/merged/data /srv/status-1/merged sudo rm -rf /srv/status-1/top /srv/status-1/work sudo mkdir /srv/status-1/top /srv/status-1/work sudo mount -t overlay overlay -o lowerdir=/srv/status-files,upperdir=/srv/status-1/top,workdir=/srv/status-1/work /srv/status-1/merged sudo mount --bind /srv/status-keep /srv/status-1/merged/data -
In terminal 1, start the app the same way as in step 5:
-
It's clean again. Now check the whole card at once with the lab's
check.sh: 14 checks of the five rows:<!doctype html><title>Status</title><h1>Status: OK</h1> ok the app runs: process 20747 on the server ok the page answers at 10.0.0.2:8000 ok nothing listens on the server's own port 8000 ok its root folder is /srv/status-1/merged ok that folder is stacked: our files below, a top folder above ok inside, it is process 1 (NSpid: 20747 1) ok inside, ps lists one python3 ok it is in the group /status ok memory.max is 67108864 ok cpu.max is 50000 100000 ok it runs as user 10001 (status) ok it has none of root's powers ok the request is in /srv/status-keep/requests.log ok its own namespaces: mnt, net and pid 0 failed
Why. An overlay shows the folders stacked as one. The app reads through the top folder to our files below, and a change is copied up into the top folder first: copy-on-write. Throw the top away, and the next start is clean, while our files and the folder we keep never change. That's a container by hand: 28 commands. The lab's build.sh holds the first 27, the clean way, and launch.sh the 28th.
Extra: all 28 commands in one go¶
clean.sh takes everything apart, and build.sh puts it back, the way the video's list does it. In terminal 2:
In terminal 1, start the app with launch.sh, the 28th command:
Then, in terminal 2, check it again. It passes all 14 checks:
Mission 9. Pack it: the image¶
8 minutes
You install Docker, and build an image from your own files with the video's five-line recipe.
-
Install Docker Engine from Docker's own package repository, as Docker's install page says. Our container keeps running:
-
Get the image's files ready: our app in a build folder, the recipe next to it, and every other file of our folder in one archive. The image's
/datamust belong to the app's user, because Docker copies its owner to a new volume:sudo chown 10001:10001 /srv/status-files/data sudo mkdir -p /srv/status-build/app sudo cp /app/status.py /app/message.txt /srv/status-build/app/ sudo cp Dockerfile /srv/status-build/ sudo tar -C /srv/status-files --exclude=./app -cf /srv/status-build/python-files.tar . cat /srv/status-build/DockerfileFROM scratch ADD python-files.tar / COPY app/ /app/ USER 10001:10001 CMD ["python3", "/app/status.py", "--listen", "0.0.0.0"]FROM scratchmeans no base image: the image starts empty, like our folder in mission 2. -
Build it, and look at its layers:
cd /srv/status-build sudo docker build -t status:1.0 . sudo docker image history status:1.0 sudo docker image inspect status:1.0 --format '{{.Config.User}} {{json .Config.Cmd}}'IMAGE CREATED CREATED BY SIZE COMMENT 94484f36f683 1 second ago CMD ["python3" "/app/status.py" "--listen" "… 0B buildkit.dockerfile.v0 <missing> 1 second ago USER 10001:10001 0B buildkit.dockerfile.v0 <missing> 1 second ago COPY app/ /app/ # buildkit 16.4kB buildkit.dockerfile.v0 <missing> 1 second ago ADD python-files.tar / # buildkit 45.4MB buildkit.dockerfile.v0 10001:10001 ["python3","/app/status.py","--listen","0.0.0.0"]Two layers of files, our folder and our app, and two settings: the user and the start command.
-
Change the message, and build version 1.1:
echo "Status: all systems normal" | sudo tee /srv/status-build/app/message.txt sudo docker build -t status:1.1 . sudo docker image ls statusStatus: all systems normal ... IMAGE ID DISK USAGE CONTENT SIZE EXTRA status:1.0 94484f36f683 60.2MB 14.9MB status:1.1 1619f9b0d7d0 60.2MB 14.9MBIn the build's output, the big layer says
CACHED: Docker built only the small one again. Each image lists 60.2MB, the big layer included, but the server stores that layer once. -
Go back to the lab's folder:
Why. An image is our folder, packed: its files as layers, plus the settings to start it. A layer is stored once and shared, so version 1.1 adds only our app's few kilobytes, and a server that has version 1.0 downloads only the new layer.
Extra: a registry¶
A registry stores images for other servers to download. Run one, as a container:
Then push both versions to it:
sudo docker tag status:1.0 localhost:5000/status:1.0
sudo docker push localhost:5000/status:1.0
sudo docker tag status:1.1 localhost:5000/status:1.1
sudo docker push localhost:5000/status:1.1
curl http://127.0.0.1:5000/v2/status/tags/list
The second push says Layer already exists for the big layer, and the registry lists both tags: {"name":"status","tags":["1.0","1.1"]}.
Mission 10. One command¶
5 minutes
You start the app with Docker: one command for the five things you did by hand.
-
Run it: a name, a memory limit, half a CPU, a port on the server's 127.0.0.1, and a volume for the log:
time sudo docker run -d --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0A tenth of a second. Ask for the page, and read what the app printed:
<!doctype html><title>Status</title><h1>Status: OK</h1> 172.17.0.1 - - [18/Nov/2026 12:06:31] "GET /status HTTP/1.1" 200 -The client is
172.17.0.1: Docker's own bridge,docker0. The time is in UTC. -
Who carries your request to port 8000 inside:
docker0 UP 172.17.0.1/16 ... LISTEN 0 4096 127.0.0.1:8080 0.0.0.0:* users:(("docker-proxy",pid=30577,fd=7))docker-proxyis a forwarding program: it listens on the server's port 8080, and passes each request on to the container. -
What's left running for the container:
D=$(sudo docker inspect status --format '{{.State.Pid}}') ps -o pid,ppid,user,args -p $D ps -o pid,args -p $(ps -o ppid= -p $D) pgrep -x runcPID PPID USER COMMAND 30632 30607 status python3 /app/status.py --listen 0.0.0.0 PID COMMAND 30607 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 1c8efae9d5cc... -address /run/containerd/containerd.sockdockerasked Docker Engine, which asked containerd, which ranrunc.runcset up the container and is gone:pgrepfinds nothing. A small watcher, the shim, stays as the app's parent. -
Both apps, side by side, ours and Docker's:
PID USER COMMAND 20747 status python3 /app/status.py --listen 0.0.0.0 30632 status python3 /app/status.py --listen 0.0.0.0The same line twice: only the number is different.
-
Docker sets only the limits you ask for. A container started with no
--memorygets none: -
Everything Docker set up for
statusis in one settings file,config.json, the fileruncread:
Why. docker run does the same five things you did by hand: a stacked folder from the image, a namespace for each list, a control group with the limits, the user, and a network with a port. The work is split among programs: docker only asks, Docker Engine and containerd prepare, and runc makes the container from config.json and exits.
Mission 11. Stop it, remove it, keep the data¶
6 minutes
You change the container, stop it, remove it, and see what stays.
-
Change the message inside, as root, and see what changed:
sudo docker exec --user 0 status sh -c 'echo "Status: MAINTENANCE" > /app/message.txt' curl http://127.0.0.1:8080/status sudo docker diff statusCis for changed, in the container's top folder. -
Stop it:
time sudo docker stop status sudo docker ps -a --filter name=status --format "table {{.Names}}\t{{.Status}}"Ten seconds. Docker sent the usual signal, our app ignored it as process 1, like in mission 4, and after 10 seconds Docker killed it. 137 means stopped by force.
-
Start it again:
It's the same container, with the same top folder:
-
Remove it, and run a new one from the image:
sudo docker rm -f status sudo docker run -d --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0Ask the new one for the page, and read the log in the volume:
<!doctype html><title>Status</title><h1>Status: OK</h1> 2026-11-18T12:06:31Z 172.17.0.1 GET /status 2026-11-18T12:06:32Z 172.17.0.1 GET /status 2026-11-18T12:06:43Z 172.17.0.1 GET /status 2026-11-18T12:06:44Z 172.17.0.1 GET /statusA clean start, and the log is still there: the volume is Docker's folder we keep.
-
Now with
--init: Docker starts a tiny program as process 1, and it starts our app and passes signals on:sudo docker rm -f status sudo docker run -d --init --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0Look inside, and stop it:
sudo docker exec status ps time sudo docker stop status sudo docker ps -a --filter name=status --format "table {{.Names}}\t{{.Status}}"PID USER COMMAND 1 10001 /sbin/docker-init -- python3 /app/status.py --listen 0.0.0.0 7 10001 python3 /app/status.py --listen 0.0.0.0 8 10001 ps status real 0m0.064s ... NAMES STATUS status Exited (143) Less than a second agoIt stops at once. 143 means stopped by the usual signal.
-
Run it again the plain way, for the next missions:
sudo docker rm status sudo docker run -d --name status --memory 64m --cpus 0.5 -p 127.0.0.1:8080:8000 -v status-data:/data status:1.0Then ask for the page:
Why. A container is a top folder over the image, like ours in mission 8. Stop and start keep it, and docker rm throws it away, so the next container starts clean. What must stay goes in a volume. Process 1 ignores signals it didn't ask for, in Docker too, so a real app either handles them or runs with --init.
Mission 12. Open it: the same parts¶
6 minutes
You open Docker's container and fill the card's second column, row by row, with the commands you used on your own.
-
Docker's app is a process on the server too. Find it, and read the values you know from
config.json(jqpicks them out of the file):D=$(sudo docker inspect status --format '{{.State.Pid}}') ID=$(sudo docker inspect status --format '{{.Id}}') sudo jq '{args: .process.args, user: .process.user.uid, namespaces: [.linux.namespaces[].type], memory: .linux.resources.memory.limit, cpu: .linux.resources.cpu}' /run/containerd/io.containerd.runtime.v2.task/moby/$ID/config.json -
Files: stacked folders, as in mission 8. Three at the bottom, and one on top for this container:
sudo grep ' / / ' /proc/$D/mountinfo | grep -o -E '(lowerdir|upperdir)=[^,]*' | tr ':' '\n' sudo nsenter --target $D --all --root ls /lowerdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/33/fs /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/9/fs /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/8/fs upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/34/fs app bin data dev etc lib proc sys usrThe lowest two are the image's layers: Python's files, and our app. The one above them is Docker's own: the files every container gets, such as
/etc/hosts,/etc/hostname,/etc/resolv.conf,/devand/sys. That's whyls /showsdev,etcandsys. -
Processes: its own list, where it is process 1:
-
Network: its own, with one end of a veth pair inside,
eth0, and the other end on Docker's bridge:2: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue link/ether 06:e2:30:ab:27:78 brd ff:ff:ff:ff:ff:ff inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever 6: veth99df5ea@enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master docker0 state forwarding priority 32 cost 2 17: veth023aef9@enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master docker0 state forwarding priority 32 cost 2Inside,
eth0@if17: its other end is interface 17 on the server, andbridge linkshows 17 on Docker's bridge,docker0. The other line is the registry's container, if you ran it. -
Memory and CPU: its own control group, with your two limits:
cat /proc/$D/cgroup cat /sys/fs/cgroup/system.slice/docker-$ID.scope/memory.max /sys/fs/cgroup/system.slice/docker-$ID.scope/cpu.max0::/system.slice/docker-969c6d9039e8c2f75b8fe719cb48e070dc181dae399ae0d7cece600d7eff2cf4.scope 67108864 50000 100000The same leak as in mission 6, in Docker, ends the same way. Start a second container with the leak on. The command after the image name replaces its start command, and
--memory-swap 64mkeeps swap out of it, on a server that has swap:sudo docker run -d --name leaky --memory 64m --memory-swap 64m -p 127.0.0.1:8082:8000 status:1.0 python3 /app/status.py --listen 0.0.0.0 --leak-mb 10Send it eight requests:
for i in 1 2 3 4 5 6 7 8; do curl -s -o /dev/null -w "request $i: HTTP %{http_code}\n" -m 5 http://127.0.0.1:8082/status; donerequest 1: HTTP 200 request 2: HTTP 200 request 3: HTTP 200 request 4: HTTP 200 request 5: HTTP 200 request 6: HTTP 000 request 7: HTTP 000 request 8: HTTP 000Then see how it ended, read the kernel's log, and remove it:
sudo docker ps -a --filter name=leaky --format '{{.Names}}: {{.Status}}' sudo dmesg | grep "Memory cgroup out of memory" | tail -1 sudo docker rm leakyleaky: Exited (137) 3 seconds ago [ 430.752661] Memory cgroup out of memory: Killed process 24677 (python3) total-vm:84828kB, anon-rss:64868kB, file-rss:6648kB, shmem-rss:0kB, UID:10001 pgtables:188kB oom_score_adj:0 leakyRequests 1 to 5 answer, 6 to 8 don't.
Exited (137)means killed by force, and the kernel's last line names the process it killed: Docker's app, as user 10001. -
User: ours, 10001, with none of root's powers:
-
Three apps have written logs by now. Each one's
/data/requests.logis a different file on the server:sudo tail -n 1 /data/requests.log /srv/status-keep/requests.log /var/lib/docker/volumes/status-data/_data/requests.logThe clients:
127.0.0.1,10.0.0.1and172.17.0.1.
Why. Every row of Docker's column holds the same Linux parts you used by hand: an overlay, namespaces, a control group, a user and a veth pair. Docker found them in your image and your docker run, wrote them into config.json, and runc asked the kernel for each one.
Mission 13. What Docker adds¶
6 minutes
You compare the two containers, and see what Docker does that our 28 commands don't.
-
Ours has three namespaces of its own. Docker's has seven:
H=$(pgrep -o -f '^python3 /app/status') D=$(sudo docker inspect status --format '{{.State.Pid}}') sudo lsns -p $H sudo lsns -p $Dutsis one of Docker's extra four: the server's name. So Docker's container has a name of its own: -
Root inside ours renamed the server in mission 7. Inside Docker's, root can't:
sudo docker exec --user 0 status hostname broken sudo docker exec --user 0 status date -s "2030-01-01 00:00:00" hostname sudo docker exec status datehostname: sethostname: Operation not permitted date: can't set date: Operation not permitted Tue Jan 1 00:00:00 UTC 2030 server-1 Wed Nov 18 12:07:07 UTC 2026BusyBox's
datestill prints the time it was given, but the clock didn't change: the last line is today's date. The container has no time zone of its own, so it shows UTC. -
Docker gives root inside only some powers, and a filter of system calls. Compare the two apps:
CapBndis the most any process inside may get: all 41 powers for ours, 14 for Docker's.Seccomp: 2means a filter checks every system call. -
One kernel, for the server and both containers:
-
A second container from the same image takes one command, and shares its layers:
Ask it for the page, and list the apps and the containers:
curl http://127.0.0.1:8081/status ps -o pid,user,args -p $(pgrep -d, -f '^python3 /app/status') sudo docker ps -s --filter name=status --format "table {{.Names}}\t{{.Size}}"<!doctype html><title>Status</title><h1>Status: OK</h1> PID USER COMMAND 20747 status python3 /app/status.py --listen 0.0.0.0 33317 status python3 /app/status.py --listen 0.0.0.0 35545 status python3 /app/status.py --listen 0.0.0.0 NAMES SIZE status2 12.3kB (virtual 45.4MB) status 4.1kB (virtual 45.4MB)The three lines from the start of the video: one by hand, two by Docker. Each container has only its small top folder; the 45 MB below is shared.
Why. A container isn't a thing in Linux. It's a process started with the parts you used: a folder, namespaces, a control group and a user. Docker doesn't do a job Linux can't do. It does the same job in one command, every time the same way, with safer defaults, like a namespace for the name and fewer powers for root, and it packs the files as an image any server can download.
Clean up¶
Delete Docker's containers and its volume first, then take the hand-built container apart with clean.sh, from the lab's folder:
If you did the registry extra, remove it too, with its volume: sudo docker rm -f -v registry. Easier still, delete the whole server. On your computer:
Free. Unsubscribe anytime. Form not loading? Subscribe here.