Every level, in the open
Docker & Containers
13 worlds · 114 levels · 13 bosses
SOLUTION HIDDENTeachers see answer keys in the classroom.
Build containers from scratch (chroot, namespaces, cgroups, layers, your own mini-docker), then ship with the real thing: Dockerfiles, ports, volumes, day-2 ops. Honest note: docker here is podman, a real engine with the same commands; no internet, so images come from local tarballs.
Guided levels show the command first. Alone levels give the goal only. Bosses and exams are timed.
Jump to a world
World 1The Jail
7 levelsA container starts as a folder that a process believes is the whole world: chroot, libraries, busybox and /proc.
Level 1: A room with no doors
Objective: Enter the jail ~/jail/rootfs with chroot and, from inside, create the file /hello.
A container is a process that sees a different /: a whole root filesystem living in one folder. sudo chroot DIR CMD runs CMD with DIR as its /.
Commands taught
rootfschrootLevel 2: Bring your own shell
Objective: Make the empty jail ~/jail/empty work (ldd shows what its shell needs), so sudo chroot ~/jail/empty /bin/sh starts a shell.
Inside a jail, a program finds nothing from the outside world, not even its shared libraries. ldd PROGRAM lists the libraries it needs, and they must sit at the same paths inside.
Commands taught
lddLevel 3: A hundred tools in one
Objective: Give the jail ~/jail/tools its commands with busybox, so ls works inside it.
busybox is one program that acts as ls, cat, ps and 300 more, depending on the name you call it by. busybox --install -s creates all those names as links.
Commands taught
busyboxLevel 4: Bash behind bars
Objective: Make bash run inside ~/jail/bashroom, so hidden prints hi.
Bigger programs need several libraries, and ldd gives each one's full path. Copy every one, keeping its path (cp --parents helps).
Level 5: The window in the wall
Objective: Make ps work inside ~/jail/rootfs by mounting proc on its /proc.
ps reads /proc, and a jail's /proc is empty until you mount it: mount -t proc proc DIR/proc. Then look closely: a chroot hides files, not processes.
Commands taught
proc-mountLevel 6: A curtain, not a wall
Objective: From inside the jail ~/jail/rootfs (proc is already mounted), read the warden's code in the host's /root/warden.txt and tell Kern: kern <code>.
/proc/PID/root is a door into the / of process PID, and PID 1 started outside the jail: from inside, /proc/1/root leads back to the host's /. That's why chroot alone is not a container; real runtimes use pivot_root inside namespaces (Hall of Masks).
Commands taught
chroot-escapeLevel 7: Build a cell
Objective: Turn the empty ~/jail/cell into a jail where /bin/sh and ls work, /etc/hostname says cell, and proc is mounted.
No help this time: a jail from an empty folder.
World 2Hall of Masks
12 levelsNamespaces give a process its own hostname, process list, mounts, network and even its own root user.
Level 8: Everyone wears masks
Objective: Find the number of your shell's uts namespace and tell Kern: kern <number>.
A namespace is a private view of one kind of thing (uts = hostname, pid = process list, mnt = mounts, net = network, user = user ids), and every process sits in one of each. hidden shows your shell's; two processes share a namespace when the numbers in brackets match.
Commands taught
namespacesLevel 9: A new name tag
Objective: Start sleep 7101 with unshare in its own UTS namespace, hostname mask, without renaming rootspire.
unshare starts a command in new namespaces; -u gives it a new UTS namespace, so its hostname changes only there. That's docker run --hostname.
Commands taught
unshareLevel 10: Process number one
Objective: Run sleep 7102 in a new PID namespace where it is PID 1.
A new PID namespace numbers processes from 1, and its processes can't see anything outside. unshare -p -f --mount-proc forks the command as PID 1 and gives it a matching /proc.
Commands taught
pid-namespaceLevel 11: Private mounts
Objective: Run sleep 7103 in its own mount namespace with a tmpfs mounted on /mnt that the host can't see.
unshare -m gives a process its own copy of the mount table: what it mounts, the host never sees. That's how docker run -v and the container's own / stay private.
Commands taught
mount-namespaceLevel 12: A real wall
Objective: Run sleep 7108 in its own mount namespace with ~/masks/rootfs as its / (pivot_root) and the old / unmounted.
pivot_root makes a folder the new / of a private mount namespace and moves the old / onto a subfolder, which you then unmount: the host's files are gone from that world, not just hidden. The new root must be a mount point, so bind-mount the folder onto itself first.
Commands taught
pivot-rootLevel 13: Visitor's tour
Objective: A container is running sleep 7110. Visit its UTS namespace, read its hostname, and tell Kern.
Four moves you'll need next, one at a time: unshare -r (a user namespace where you are root), unshare -n (a network namespace with nothing in it), ip netns (names for those), and nsenter (visit a running container).
Commands taught
netnsLevel 14: Root without sudo
Objective: Without sudo, write what id -u prints inside a user namespace into ~/masks/fakeroot.txt.
A user namespace maps your user to root inside it: unshare -r makes you uid 0 there, with no sudo. It's root only over your own things: that's how rootless containers work.
Commands taught
user-namespaceLevel 15: Who's who
Objective: Without sudo, start sleep 7105 in a new user namespace (unshare -U … &), then write its uid_map so uid 0 inside is you (uid 1000) outside.
unshare -r is two steps: unshare -U makes a user namespace where nobody is mapped yet, then a line 'INSIDE OUTSIDE COUNT' in /proc/PID/uid_map maps ids ('0 1000 1': uid 0 inside is you outside). You may write that one line for your own uid without sudo.
Commands taught
uid-mapLevel 16: Into the vault
Objective: A container is running sleep 7104: enter its mount namespace and tell Kern the code in its /mnt/code.txt.
nsenter -t PID joins the namespaces of a running process (-m mounts, -u uts, -p pid, -n net). It's what docker exec does.
Commands taught
nsenterLevel 17: A network of one
Objective: Create the network namespace pod and bring its lo interface up.
ip netns add NAME creates a network namespace: an empty network stack with just a lo that's down. ip netns exec NAME CMD runs inside it, like docker run --network none.
Commands taught
netnsLevel 18: The inspector
Objective: Find the hostname of the container running sleep 7107 and tell Kern.
Quick: a container is up and nobody knows its name.
Level 19: The masquerade
Objective: Without sudo, run sleep 7109 as PID 1 of its own user, PID, mount, UTS and network namespaces, with hostname ghost.
Every mask at once, and no sudo.
World 3The Scales
10 levelsControl groups weigh what each container may use: processes, memory and CPU, all through plain files.
Level 20: The weighing room
Objective: Create the cgroup box.
Control groups (cgroups) put processes in groups and limit what a group may use. In cgroup v2 a group is just a folder under /sys/fs/cgroup: mkdir creates it and the kernel fills it with knob files.
Commands taught
cgroupsLevel 21: Into the box
Objective: Move the running sleep 7201 into the cgroup box.
A process joins a group when you write its PID into the group's cgroup.procs, and /proc/PID/cgroup shows where it lives. Root owns those files, so write with echo PID | sudo tee FILE.
Commands taught
cgroup-procsLevel 22: Fork bomb shield
Objective: Limit the cgroup box to at most 5 processes.
pids.max caps how many processes a group may have; past it, fork fails. A container with a pid limit survives a fork bomb (docker run --pids-limit).
Commands taught
pids-maxLevel 23: Boxes in boxes
Objective: Create the cgroup yard with a child yard/web that has its own pids.max and memory.max knobs.
mkdir inside a group makes a child group, but a child only gets the knobs (memory.max, pids.max…) of controllers listed in its parent's cgroup.subtree_control: echo '+memory +pids' into it. Docker nests like this: one parent group, one child per container.
Commands taught
subtree-controlLevel 24: Reading the gauges
Objective: Of box and tenant, one holds a lot of memory and the other has burned CPU: tell Kern which is which with kern <memory hog> <cpu hog>.
Groups don't only limit, they measure. memory.current is how many bytes the group uses right now, and the usage_usec line of cpu.stat is the CPU time it has burned, in microseconds. docker stats (and kubectl top) read exactly these files.
Commands taught
cgroup-statsLevel 25: Memory diet
Objective: Cap the cgroup lab at 16 MiB of memory.
memory.max is the most a group may use; past it the kernel reclaims, then kills a process (the OOM killer). It accepts suffixes like 16M (docker run --memory 16m).
Commands taught
memory-maxLevel 26: The slow lane
Objective: Give the cgroup render a CPU weight of 20.
cpu.weight sets a group's share of the CPU when everyone is busy: default 100, so 20 gets a fifth as much (docker run --cpu-shares, converted: 1024 shares = weight 100). The hard cap, cpu.max (--cpus), is left out of this little kernel.
Commands taught
cpu-weightLevel 27: Post-mortem
Objective: Programs in the cgroup lab keep dying: tell Kern how many were killed for running out of memory.
Each group keeps score in memory.events: the oom_kill line counts processes killed for using too much memory. That's what docker inspect calls OOMKilled.
Commands taught
memory-eventsLevel 28: Noisy neighbour
Objective: Put sleep 7207 in a new cgroup tenant limited to 10 processes and 32 MiB of memory.
A new tenant moves in. Fence it before it gets loud.
Level 29: Scales of justice
Objective: Move sleep 7208 from lab into a new cgroup slow with 64 MiB and a CPU weight of 50, then tell Kern how many OOM kills lab has seen.
A job is starving in a group too small for it.
World 4The Layer Cake
7 levelsOverlayFS stacks read-only layers under one writable layer: exactly how Docker images and containers share files.
Level 30: Stacking glass
Objective: Mount an overlay on ~/layers/merged with lower as the bottom layer and upper for changes (work is the workdir).
An overlay mount shows several folders as one: lowerdir is read-only, upperdir catches every change, workdir is overlay's scratch space, and the result appears at the mount point. Docker's image is the lower part, the container's own layer is the upper.
Commands taught
overlayfsLevel 31: Copy-up
Objective: Change ~/layers/merged/motd.txt to say patched, leaving the lower layer untouched.
Lower layers are never changed: when you edit a lower file through the overlay, it's first copied up into upper, then changed there. That's why a hundred containers can share one image.
Commands taught
copy-upLevel 32: Ghost files
Objective: Delete junk.bin from ~/layers/merged without touching the lower layer.
Deleting a lower file can't touch the lower layer, so overlay leaves a whiteout in upper: an empty special file with the same name that means 'hide this'. ls -l shows it with a c (character device) and the numbers 0, 0.
Commands taught
whiteoutLevel 33: Many layers
Objective: Mount ~/layers/merged with app stacked on top of base (and upper, work for changes), so merged/version.txt comes from app.
lowerdir can take several folders separated by colons, and the FIRST one is the top. Every Dockerfile instruction adds one such layer on top of the previous ones.
Commands taught
overlay-lowersLevel 34: Frozen image
Objective: Mount ~/layers/ro as a read-only stack with app on top of base.
Without upperdir and workdir an overlay is read-only: just the image's layers. Docker keeps images like that and adds a fresh upper per container.
Level 35: Upside down
Objective: ~/layers/view has its layers upside down (version base, debug=true): remount it read-only with patch on top of app on top of base.
A read-only view was mounted in a hurry, and the app now runs with the wrong settings. Find out where the files come from and fix the stack.
Level 36: The layer cake
Objective: Mount ~/layers/box with app stacked on base plus your own upper, then from inside it (chroot) write cake into /etc/motd and delete /app/old.sh.
Run a container on a two-layer image, the way Docker does. Nothing is prepared this time: you make your own upper, work and mount-point folders.
World 5The Cargo Bay
9 levelsAn image is a stack of tarballs plus a list of fingerprints: pack, unpack, layer, whiteout and verify them by hand.
Level 37: Pack it up
Objective: Pack the root filesystem ~/cargo/rootfs into ~/cargo/image.tar, with paths starting at its root (./bin/…).
Strip away the registry and a container image is tarballs of root filesystems. tar -C DIR -cf FILE . packs a folder's contents with paths starting at its root, like docker export.
Commands taught
image-tarballLevel 38: Unpack and look
Objective: Unpack ~/cargo/kmini.tar into ~/cargo/run and tell Kern the PRETTY_NAME in the image's /etc/os-release.
Running an image starts with unpacking it: tar -C DIR -xf FILE extracts into DIR. Then chroot into DIR and you're inside the image.
Level 39: Layer by layer
Objective: Rebuild the image in ~/cargo/stack by unpacking layer1.tar, then layer2.tar on top.
A real image is several layer tarballs; unpacking them in order into one folder rebuilds its filesystem, and later layers overwrite earlier files. Each Dockerfile line (FROM, COPY, RUN) made one of them.
Commands taught
image-layersLevel 40: A note that deletes
Objective: Apply ghost.tar to ~/cargo/stack: unpack it, then do what its one .wh. marker says, by hand, and remove the marker.
A layer tarball can't hold 'nothing', so it marks a deletion with an empty file named .wh.NAME next to where NAME was: it means 'delete NAME'. tar doesn't know that rule: after unpacking, the engine deletes NAME and removes the marker.
Commands taught
oci-whiteoutLevel 41: Whiteout notes
Objective: Apply layer3.tar to ~/cargo/stack the way Docker does: every .wh.NAME deletes NAME, and no .wh. files remain.
Same rule as the last level, more markers: every .wh.NAME in the layer means 'delete NAME'. After unpacking, apply each one and remove the marker. hidden lists them all.
Level 42: Clean slate
Objective: Apply layer4.tar to ~/cargo/stack the way Docker does: its app/ has an opaque marker, so afterwards app/ holds only what layer4 brings, and no marker.
A layer that replaces a whole folder puts one opaque marker in it: .wh..wh..opq means 'forget everything earlier layers put in this folder'. Apply it by emptying the folder BEFORE unpacking the layer, then remove the marker.
Level 43: Fingerprints
Objective: Write ~/cargo/manifest.txt with one line per layer, layer1.tar to layer3.tar in order, each holding sha256:<digest> of that layer.
Images name their layers by content: the sha256 digest of each tarball (sha256sum FILE), and a manifest is the ordered list of those digests. Ours is the simple version: a real OCI manifest is JSON, with gzip layers and a config file.
Commands taught
digestLevel 44: Tampered cargo
Objective: One layer in ~/cargo/shipment doesn't match its digest in manifest.txt: tell Kern its file name.
Someone opened a crate on the dock.
Level 45: Ship it
Objective: Unpack the image in ~/cargo/ship into ~/cargo/live in manifest.txt order, honouring whiteouts, then run /app/run.sh inside it with chroot.
A whole image, crate by crate.
World 6The Dock
9 levelsEverything you built, in one script: minidock pulls images and runs them with namespaces, cgroups and a container layer.
Level 46: minidock run
Objective: Fill in TODO L1 of ~/bin/minidock (shift already ran; exec chroot) so sudo ~/bin/minidock run ~/dock/rootfs CMD… runs CMD in that folder, exit code kept.
docker run glues together tricks you already know, and Kern's skeleton in ~/bin/minidock has TODO lines tagged L1 to L9, one set per level of the Dock. Step one is the oldest trick: chroot into the root filesystem it's given and exec the command there.
Commands taught
minidockdocker-mapLevel 47: Masks on
Objective: Fill in TODO L2: minidock run must start the command in new UTS, PID and mount namespaces, still chrooted into the rootfs.
A container gets its own namespaces before it gets its root. Put unshare -u -p -m -f in front of chroot: the command is then PID 1 of a new PID namespace, and hostnames and mounts made inside stay inside.
Level 48: A fresh /proc
Objective: Fill in TODO L3: inside the chroot, mount a fresh proc on /proc, then exec the command, so ps in the container shows only its own processes.
To mount proc inside the container, minidock needs a tiny shell script to run there first: /bin/sh -c 'mount -t proc proc /proc; exec "$@"', followed by the command. sh -c 'SCRIPT' A B C sets $0=A and $@=B C, so put a placeholder word (sh) before the command.
Level 49: Name tags, again
Objective: Teach minidock run a --hostname NAME flag (docker run --hostname), keeping everything that already works.
Flags turn into kernel settings: --hostname NAME becomes a hostname call inside the new UTS namespace. Parse flags in a while loop before the rootfs argument.
Level 50: Weights and measures
Objective: Add --memory SIZE and --pids N to minidock run, applied through a cgroup per container.
--memory and --pids become a cgroup: make /sys/fs/cgroup/minidock/<id>, write memory.max and pids.max, and move the script itself in before it starts the container (children inherit the group). minidock is the yard, each container a pen (Boxes in boxes).
Level 51: Pull
Objective: Add minidock pull TAR NAME (unpack into /var/lib/minidock/images/NAME) and let run take an image name.
Engines keep images by name in their own folder (Docker: /var/lib/docker). Here that's /var/lib/minidock, a tmpfs: pull TAR NAME unpacks into images/NAME, and run accepts a NAME.
Level 52: The container layer
Objective: Make minidock run IMAGE use an overlay with a fresh upper per container, so the image never changes.
Right now a container can scribble on its image. Docker never lets that happen: each run mounts an overlay with the image as lowerdir and a fresh upper for that container.
Level 53: Leave no trace
Objective: Fill in TODO L8: minidock run returns the container's exit code and does rmdir on its cgroup, leaving none in /sys/fs/cgroup/minidock.
For --rm, minidock must outlive its container: no exec in front of unshare, and rc=$? keeps the exit code. A cgroup can only be removed when empty and the script sits in it, so move $$ back to the root group, remove the container's group, then exit $rc.
Level 54: Ship it
Objective: Pass the full inspection: pull, run with every flag on a container layer, return the exit code, and leave no mount, folder or cgroup behind (docker run --rm).
The full inspection: every feature at once, and a clean dock afterwards. Your TODO L9 line is the last piece: like the cgroup, a container layer must go when its container ends.
World 7The Recipe
9 levelsWrite Dockerfiles, the recipes a real engine follows to bake images, and run what comes out.
Level 55: First recipe
Objective: In ~/recipe, write a Dockerfile FROM busybox whose CMD is ["echo", "hello from my image"], build it as hello and run it.
A Dockerfile is a recipe: FROM picks the base image, CMD is the command a container runs by default. docker build -t NAME . bakes the recipe in this folder into an image, and docker run NAME starts a container from it.
Commands taught
docker-is-podmandockerfiledocker-builddocker-runLevel 56: Bring your own files
Objective: Build cafe:1 FROM busybox with ~/recipe/index.html copied to /www/index.html and CMD ["cat", "/www/index.html"].
COPY SRC DEST copies files from the build context (the folder you build) into the image. Paths on the left are relative to that folder; the right side is a path inside the image.
Commands taught
df-copyLevel 57: Every RUN a layer
Objective: Build cafe:2 from cafe:1's recipe plus a RUN that writes soup of the day into /www/menu.txt, then list its layers with docker history.
RUN runs a command inside the image while it's being built, and the files it changes become a new layer. docker history IMAGE lists the layers, newest first, with the instruction that made each one and its size.
Commands taught
df-rundocker-historyLevel 58: Pick a workbench
Objective: Build cafe:3 FROM busybox with WORKDIR /www, index.html copied there with a relative path, and CMD ["ls"].
WORKDIR /www makes /www the current folder for the next instructions and for the running container (it creates it if needed). After it, COPY index.html . lands in /www.
Commands taught
df-workdirLevel 59: A value from outside
Objective: Run stamp:9 and read its /version.
ARG NAME=default declares a build-time value; docker build --build-arg NAME=value overrides it. It exists only while the image is built.
Commands taught
df-argLevel 60: House settings
Objective: Build greeter (it runs ~/recipe/greet.sh) with GUEST=stranger as its default, then run it once with GUEST set to Ada.
ENV NAME=value bakes an environment variable into the image, as a default. docker run -e NAME=other overrides it for one container, without rebuilding.
Commands taught
df-envLevel 61: Build-time knobs
Objective: Build cafe:2.1 whose /version file holds 2.1, set with --build-arg VERSION=2.1 (the Dockerfile's default stays dev).
ARG NAME=default declares a build argument: RUN steps can read $NAME, and docker build --build-arg NAME=value changes it. Unlike ENV it's gone when the container runs.
Level 62: Kitchen disaster
Objective: Fix ~/recipe/Dockerfile so hidden works and running cafe:fixed prints the café page.
Someone wrote this recipe in a hurry. Read the build errors: they name the line that failed.
Level 63: Opening night
Objective: Write ~/recipe/Dockerfile for cafe:1.0: the site in /www, a version stamp from --build-arg, a GREETING default and a web server command.
Put every recipe step together: the café's site, a version stamp, a default setting and a server command.
World 8The Kitchen
9 levelsFiner recipes: who is PID 1, entrypoints, users, ports on paper, two-stage builds and the build cache.
Level 64: Who is PID 1?
Objective: Build kitchen:2 from ~/kitchen so app.sh is PID 1 (WORKDIR /app plus an exec-form CMD) and docker stop ends it cleanly with exit code 0.
CMD in shell form (CMD cd /app && ./app.sh) runs /bin/sh -c as PID 1, and that shell neither handles nor passes on the SIGTERM that docker stop sends, so after 10 s Docker kills it (exit 137). Exec form (CMD ["./app.sh"]) makes your app PID 1, so its TERM handler runs.
Commands taught
df-cmd-formsLevel 65: The house blend
Objective: Build brew from ~/kitchen/brew.sh with ENTRYPOINT ["/brew.sh"] and CMD ["espresso"], run it plain, then run it once asking for latte.
ENTRYPOINT ["prog"] is the program that always runs; CMD ["arg"] becomes its default arguments. docker run IMAGE latte replaces only the CMD, so the image behaves like a command.
Commands taught
df-entrypointLevel 66: Not the head chef
Objective: Build cook:1 FROM busybox that adds the user cook with uid 10001, runs as cook and has CMD ["id", "-u"].
Containers run as root (uid 0) unless the image says otherwise, and that root is the host's root if anything breaks out. RUN adduser makes a user and USER NAME switches every later step and the container to it.
Commands taught
df-userLevel 67: Ports on paper
Objective: Build menu:1 with EXPOSE 8080, then find which port the image mystery:1 documents and tell Kern with kern PORT.
EXPOSE 8080 only writes into the image's settings which port the app listens on: it opens nothing. docker inspect shows it under ExposedPorts; publishing a port is docker run -p.
Commands taught
df-exposedocker-inspectLevel 68: Two kitchens
Objective: Build menu:2: compile menu.kc with kern-cc in a kern/sdk:1 stage named build, then copy only /menu into busybox as /usr/local/bin/menu, CMD ["menu"].
A multi-stage Dockerfile has several FROM lines: an early stage (FROM sdk AS build) has the heavy tools and builds the program, and the last stage only does COPY --from=build of the result. Only the last stage ends up in the image.
Commands taught
df-multistageLevel 69: Not in my soup
Objective: Without touching the Dockerfile, make hidden give an image with no secrets.env and no logs/ in /app.
docker build sends the whole context folder to the engine, and COPY . copies all of it. A .dockerignore file next to the Dockerfile lists paths to leave out (secrets.env, logs/, .git), like .gitignore.
Commands taught
dockerignoreLevel 70: Prep before service
Objective: Reorder ~/kitchen/Dockerfile so install.sh runs after copying only deps.txt and install.sh, with the rest copied after it, and build it as shop:2.
Each step is cached and reused until one of its inputs changes; then that step and every step after it rebuild. So copy what changes rarely (the dependency list) and install it first, and copy the code that changes often last.
Commands taught
build-cacheLevel 71: Diet plan
Objective: Build menu:slim under 3 MB that still prints the menu from ~/kitchen/menu.kc when run.
The menu image ships the whole toolchain. Make it small without changing what it prints.
Level 72: Health inspection
Objective: Build cafe:2.0 from ~/kitchen: a two-stage menu program, run as cook, menu as the ENTRYPOINT, port 8080 documented and the site files with no secrets.
The inspector checks every rule of a good image: small, not root, a real PID 1, documented ports, no secrets, cache-friendly order.
World 9The Wiring
10 levelsPlug real containers into a bridge by hand: cables, addresses, routes and NAT, exactly what docker run does for you.
Level 73: A cable in the wall
Objective: Make a veth pair kv-web on the host whose other end is eth0 inside the container web.
A container started with --network none has only lo. Docker gives it a network with a veth pair: one end stays on the host, the other is moved into the container's network namespace, found through its PID (docker inspect).
Commands taught
wire-pidwire-vethLevel 74: The switchboard
Objective: Create the bridge dock0 with 172.18.0.1/24, bring it up, and plug kv-web into it (up too).
Docker plugs every container's host-side veth into one bridge, docker0, which acts as a switch and holds the containers' gateway address. We call ours dock0, with 172.18.0.1/24.
Commands taught
wire-bridgeLevel 75: An address
Objective: Give web's eth0 the address 172.18.0.2/24 and bring it up, so the host can reach http://172.18.0.2/.
Inside the container, eth0 needs an address on the bridge's subnet and must be up; Docker hands out 172.17.0.2, .3 and so on. nsenter -t PID -n runs ip inside the container's network namespace, as root.
Commands taught
wire-ipLevel 76: The way out
Objective: Give web a default route via 172.18.0.1.
A container only knows its own /24 until it gets a default route: send everything else to the gateway, the bridge's address. Docker adds default via 172.17.0.1 to every container.
Level 77: A rule at the door
Objective: Delete your rule again: same words, but -D instead of -A.
NAT rules live in iptables' nat table. A DNAT rule rewrites the destination of packets that match: this is how a published port reaches a container.
Commands taught
wire-dnatLevel 78: Masquerade
Objective: Let web reach the outside server isp at http://198.51.100.2/ (isp has no route back to your containers).
To reach the outside, the host must forward packets (net.ipv4.ip_forward=1) and hide the containers behind its own address, because the outside has no route back to 172.18.0.0/24. Docker adds POSTROUTING -s SUBNET ! -o docker0 -j MASQUERADE.
Commands taught
wire-masqueradeLevel 79: Publish by hand
Objective: Make port 8080 on the host's outside address 198.51.100.1 reach web's port 80, and test it from isp.
docker run -p 8080:80 adds a DNAT rule in nat PREROUTING: packets for the host's port 8080 get their destination rewritten to the container's IP and port 80. Replies are rewritten back by connection tracking.
Commands taught
wire-dnatLevel 80: Names, not numbers
Objective: Make http://api/ work from inside web (api is the container at 172.18.0.3).
Apps call each other by name, not IP. Docker's user networks answer names with a small DNS server; the older way, still used by --add-host and podman, is a line in the container's /etc/hosts.
Commands taught
wire-hostsLevel 81: Who's talking?
Objective: One container keeps calling isp: tell Kern its name with kern NAME.
Someone keeps calling the outside server. After MASQUERADE every packet looks like the host's, so sniff where the containers' own addresses are still visible.
Commands taught
wire-tcpdumpLevel 82: Wire the kitchen
Objective: Wire the container shop end to end: cable on dock0, address 172.18.0.4 with a route, and host port 9090 published to its port 80.
Do everything docker run does for networking, for a brand-new container, from cable to published port.
World 10The Ports
7 levelsPublish ports and pick network modes with one flag each, now that you know what they do underneath.
Level 83: Open the door
Objective: Run kern/cafe:1 in the background as menu with host port 8080 published to its port 80, and fetch the page with curl.
docker run -d starts a container in the background; -p 8080:80 publishes it: connections to the host's port 8080 are forwarded to port 80 inside. hidden shows the mapping in its PORTS column.
Commands taught
port-publishLevel 84: Only for us
Objective: Run kern/cafe:1 as admin, reachable only from this machine on port 8081, then check it with hidden.
-p 8080:80 listens on every address of the host, so the whole network can connect. -p 127.0.0.1:8081:80 listens on localhost only; docker port NAME shows what a container publishes.
Commands taught
port-bindLevel 85: No walls
Objective: Run kern/cafe:1 as hostweb with --network host, its httpd listening on port 8082 (httpd -f -p 8082 -h /www).
--network host skips the network namespace: the container uses the host's interfaces and ports directly, so -p does nothing. Fastest, but no isolation and port clashes are your problem.
Commands taught
port-hostLevel 86: The sidecar
Objective: Run busybox as probe (hidden00, in the background) sharing menu's network, and fetch menu's page from it on 127.0.0.1.
--network container:NAME puts a new container into NAME's network namespace: same interfaces, same localhost. A sidecar (a probe, a proxy) talks to the app on 127.0.0.1; a Kubernetes pod is built exactly like this.
Commands taught
port-containerLevel 87: Air gap
Objective: Run busybox as vault in the background (hidden00) with no network at all, then confirm inside that only lo exists.
--network none gives a container only lo: no cable, no route, nothing in or out. Batch jobs that handle secrets or untrusted files often run like this.
Commands taught
port-noneLevel 88: Connection refused
Objective: Make http://127.0.0.1:8083/ serve the café page from a container named menu (kern/cafe:1), replacing the broken one.
menu is published on 8083, yet customers get connection refused. Published traffic arrives on the container's network card, not on its localhost: a server started on 127.0.0.1 never sees it. The image's default command listens on every address.
Commands taught
port-listenLevel 89: Grand opening
Objective: Start the café's four containers with the right network for each: front, health, stats and metrics.
Four containers, four network setups: pick the right mode for each.
World 11The Holds
10 levelsContainers forget everything when they go: give them holds where data stays, from bind mounts to volumes on their own disks.
Level 90: A window to the host
Objective: Run a busybox container with ~/holds/notes mounted at /notes that writes hello from inside into /notes/inside.txt.
A container's own files vanish with it. -v /host/folder:/path mounts a host folder into the container (a bind mount): what the container writes there lands straight on the host.
Commands taught
bind-mountLevel 91: Look, don't touch
Objective: Run a container named cfg that cats /etc/app/app.conf, with ~/holds/config mounted read-only at /etc/app.
Add :ro to a mount (-v HOST:CT:ro) and the container can read it but never write: config and secrets should come in this way. docker rm NAME deletes a stopped container.
Level 92: The pantry
Objective: Create the volume pantry, write 12 jars into stock.txt on it from a busybox container, and look up its Mountpoint with docker volume inspect.
A named volume is storage the engine manages for you: docker volume create NAME makes it, -v NAME:/path mounts it (no slash in front = a volume). docker volume inspect shows its Mountpoint, the real folder on the host.
Commands taught
docker-volumeLevel 93: The ledger remembers
Objective: Write 3 coffees into sales.txt on the volume ledger from a --rm container, then read it back from a second --rm container.
Removing a container removes its top layer, never its volumes: the next container that mounts the volume finds the data. If -v names a volume that doesn't exist yet, docker creates it.
Level 94: A disk of its own
Objective: Attach /tmp/vault.img (an ext4 image) to a loop device, create the volume vault on it, and store gold in /data/gold.txt through it.
losetup -f --show FILE turns a disk image into a block device (/dev/loopN). docker volume create --opt type=ext4 --opt device=/dev/loopN NAME makes a volume that mounts that disk, like a cloud volume attached to a server.
Commands taught
block-volumeLevel 95: Memory only
Objective: Run a container named scratch, with a tmpfs at /cache, that prints df /cache.
--tmpfs /path mounts a fresh in-memory filesystem there: fast, never written to disk, gone when the container stops. Good for caches and scratch files.
Commands taught
tmpfs-mountLevel 96: Not your shelf
Objective: till:2 runs as nobody and can't write to the orders volume: fix the volume's ownership so hidden works.
Numbers, not names, own files: data a root container wrote belongs to uid 0, so an image that switches to USER nobody (65534) gets Permission denied there. Fix the data's owner, from a container: chown -R nobody /data.
Commands taught
volume-ownershipLevel 97: Pack it, unpack it
Objective: Back up the volume recipes into ~/holds/backup/recipes.tar, then restore that tar into a new volume recipes2.
To back up a volume, mount it AND a host folder into a throwaway container and tar one into the other: tar cf /backup/x.tar -C /data . Restoring is the same run backwards, into a new volume.
Commands taught
volume-backupLevel 98: Who ate the disk?
Objective: Find the volume eating the disk (tell Kern its name), remove it, and rerun scratchy with a tmpfs at /cache instead.
hidden lists every image, container and volume with its size. Throwaway cache belongs in a tmpfs, not on a volume that grows forever.
Commands taught
docker-system-dfLevel 99: Moving day
Objective: Put the café's sqlite database on its own disk, back it up, then upgrade to cafe-db:2 without losing an order.
The café's database must survive an upgrade: its own disk, a backup first, then the new version against the same data.
World 12The Shift
8 levelsNight shift on a container host: start things in the background, read their logs, step inside and stop them properly.
Level 100: Into the background
Objective: Start a background container named web from busybox running httpd -f -p 8080 -h /etc, then list the running containers.
docker run -d starts a container in the background and prints its ID; --name gives it a name you can use instead. hidden lists the running containers, hidden the stopped ones too.
Commands taught
docker-psLevel 101: What did it say?
Objective: The container chatty reported a failed order: read its logs and tell Kern the order number with kern NUMBER.
Whatever a container's main process prints goes to its log: docker logs NAME shows it all, --tail N only the last N lines, -f keeps following (Ctrl-C stops). Here podman keeps the log in a file (log driver k8s-file); Docker's default is json-file.
Commands taught
docker-logsLevel 102: Step inside
Objective: The container vault keeps a code in /data/key.txt inside it: read it with docker exec and tell Kern the code.
docker exec NAME COMMAND runs one more process inside a running container: same namespaces, same files, same cgroup (it's nsenter, from the Hall of Masks). docker exec -it NAME sh gives you a shell in there.
Commands taught
docker-execLevel 103: Lights out
Objective: Stop the container polite with docker stop and kill the container stubborn (it ignores SIGTERM) with docker kill.
docker stop sends SIGTERM, waits (10 s, or -t N) for a clean exit, then sends SIGKILL; docker kill sends SIGKILL at once. A death by signal shows as 128 + the signal: 143 for SIGTERM (15), 137 for SIGKILL (9).
Commands taught
docker-stopLevel 104: Read the label
Objective: Tell Kern the host PID of the main process of the container mystery with kern PID.
docker inspect NAME prints everything the engine knows about a container as JSON; --format (-f) picks one field with a Go template, like '{{.State.Pid}}' or '{{.Config.Env}}'.
Level 105: Settings by the file
Objective: Write ~/shift/app.env with MODE=night and WORKERS=3, and start container api from busybox (sleep 3600) in the background with that file.
--env-file PATH reads KEY=value lines from a file and sets them all, like many -e flags; it keeps settings out of your shell history and next to the app.
Commands taught
env-fileLevel 106: Morning report
Objective: Tell Kern which job hit a missing command and which one was killed: kern <127-job> <137-job>.
Four jobs ran overnight and stopped. Exit codes below 128 come from the program itself (127: command not found, 126: found but not runnable); above 128 it died from a signal (137 = SIGKILL, the OOM killer or docker kill).
Commands taught
exit-codesLevel 107: Pager at 3 a.m.
Objective: Bring the shop back: diagnose the dead container, run a fixed shop2 from the same image, check it from inside and remove the old one.
The shop container is down. Find out why, start a fixed one next to it, prove it works and clean up.
World 13The Night Watch
7 levelsKeep containers healthy all night: clean stops, reaped zombies, automatic restarts, free disk and upgrades nobody notices.
Level 108: Deaf PID 1
Objective: Add a SIGTERM trap to ~/watch/app.sh that prints bye and exits 0, rebuild watch:1 and check that docker stop is now quick.
The kernel gives PID 1 of a namespace no default signal actions: a SIGTERM it has no handler for is simply ignored, so docker stop waits 10 s and then kills it. A shell script gets a handler with trap 'cleanup; exit 0' TERM.
Commands taught
pid1-signalsLevel 109: The night porter
Objective: Start worker in the background from busybox running sleep 3600 with --init, look at its processes, then docker stop it.
docker run --init makes a tiny init (here catatonit, in Docker tini) PID 1: it passes signals on to your program and reaps zombies, the dead children nobody waited for. Your program then dies from SIGTERM normally: exit 143.
Commands taught
docker-initLevel 110: Get back up
Objective: Run flaky (busybox, sh -c 'sleep 1; exit 3') in the background with --restart on-failure:3 and tell Kern its RestartCount once it gives up.
--restart on-failure:N tells the engine to start a container again when it exits with a non-zero code, at most N times (always and unless-stopped restart on any exit). docker inspect shows the count in .RestartCount.
Commands taught
restart-policyLevel 111: Sweep the floor
Objective: Remove every stopped container and dangling image, but keep the running container keep and its image keep:1.
hidden shows the space used by images, containers and volumes, and how much is reclaimable. docker system prune removes stopped containers and dangling images (old builds with no name); volumes only with --volumes.
Commands taught
docker-pruneLevel 112: Ten long seconds
Objective: Fix ~/watch/Dockerfile so a container of slowpoke:1 (rebuilt) stops within 3 seconds of docker stop.
slowpoke's serve.sh has a trap, but docker stop still takes 10 s. Shell form CMD with && keeps /bin/sh as PID 1, and sh doesn't pass SIGTERM on.
Level 113: Disk almost full
Objective: Free at least 10 MB of engine storage without losing the orders volume or stopping the running container shop.
The engine's storage is filling up with leftovers from crashed jobs. Free space, but some unused-looking things hold real data.
Level 114: Changing the guard
Objective: Roll the café from web:1 to web:2 with no downtime: start web2 in the pod, point the proxy at it with a reload, then retire web1.
The café runs as a pod: an nginx proxy on port 8080 with web1 (version 1) behind it. Roll out version 2 without the proxy ever going down: start new, check, switch, retire old.
Commands taught
podman-pod
For teachers
Use these levels with a class
SOLUTION HIDDEN Teachers see answer keys in the classroom.