Docker from the kernel up · check

Know What a container really is already?

One question for each of the 9 puzzles in this module. A right answer marks that puzzle as passed, so you can jump ahead. A wrong one tells you which puzzle to start with. Nothing is sent anywhere: it's saved in this browser.

Puzzle 0: A container is a process

You start two containers from the same image, each running sleep 1000. How many sleep processes does the host's ps list?

Not quite. Each docker run starts its own process; the image is only files, and nothing in it runs by itself. Learn it in puzzle 0 →

Right. Two processes: one per container, both on the host's list.

Not quite. The kernel runs a container's program like any other process, and ps lists it. Learn it in puzzle 0 →

Puzzle 1: One kernel, or many?

An image made from an older Linux distribution runs on a host whose kernel is 6.18.44. What does uname -r print inside the container?

Not quite. The image brought that distribution's files, not its kernel; the host's kernel answers. Learn it in puzzle 1 →

Right. One kernel answers every container's system calls.

Not quite. uname -r makes a system call, and the shared kernel answers it. Learn it in puzzle 1 →

Puzzle 2: Whose PID 1?

A container runs a shell, sh, as its first process, and sh starts a program called worker. What PIDs does a ps inside the container show for them?

Right. Numbering starts again at 1 in the new namespace.

Not quite. PID 1 goes to the first process in the namespace: here, sh. Learn it in puzzle 2 →

Not quite. Inside, ps reads the container's own /proc, which numbers from 1 in the new PID namespace. Learn it in puzzle 2 →

Puzzle 3: A file tree of its own

Inside a container you create /tmp/notes.txt. On the host, does ls /tmp list notes.txt?

Right. The container writes into its own tree.

Not quite. Stopping changes nothing: the host's /tmp was never the container's /tmp. Learn it in puzzle 3 →

Not quite. One kernel, but two lists of mounts: the container's / is the image's files. Learn it in puzzle 3 →

Puzzle 4: A namespace per resource

A program in a container connects to localhost to reach a database that runs on the host, not in a container. Does it reach the database?

Not quite. One kernel, but the network namespace is the container's own. Learn it in puzzle 4 →

Not quite. Each network namespace has its own lo, so localhost is the container. Learn it in puzzle 4 →

Right. Inside a network namespace, localhost is that namespace.

Puzzle 5: Root in the container is root on the host

A container runs as root by default, and you mount a host folder of root-owned configuration files into it. Its program has a bug that writes to every file it can. What happens to the host's files?

Right. Same UID, same rights over the mounted files.

Not quite. A folder mounted in with -v is in the container's tree on purpose. Learn it in puzzle 5 →

Not quite. Without a user namespace, inside UID 0 is the host's UID 0, and the kernel checks files by UID. Learn it in puzzle 5 →

Puzzle 6: How much memory may it use?

A container started with a 256 MB memory limit on a 16 GB host runs a program that sizes its cache to a quarter of the total memory free reports. What happens as the cache fills?

Right. It plans from the host's figure and meets the group's limit.

Not quite. The cgroup's limit holds however much the host has free. Learn it in puzzle 6 →

Not quite. free reports the host's total; the program never sees the limit. Learn it in puzzle 6 →

Puzzle 7: How much processor time?

A Gradle build runs four busy threads in a container started with a quota of one processor (--cpus 1) on a machine with 8 free processors. Roughly how long can each thread run in each 100 ms period?

Right. Four threads share one quota.

Not quite. The free processors don't matter; only the group's 100 ms quota does. Learn it in puzzle 7 →

Not quite. The quota is counted for the group together: 100 ms per period, shared by four threads. Learn it in puzzle 7 →

Puzzle 8: Who builds the container?

You start a container with docker run -d, then close the terminal the docker command ran in. Does the container keep running?

Not quite. The docker command is a client; the container's process is the shim's child, not the command's. Learn it in puzzle 8 →

Right. The docker command isn't part of the container.

Not quite. runc exits by design after starting the program; the shim stays as its parent. Learn it in puzzle 8 →

Back to the overview →