Chapter 25. Containers and Isolated Workloads

A container is an ordinary Linux process that the kernel has been told to keep apart from its neighbors: it sees its own process tree, its own network stack, and its own root filesystem, while sharing one kernel, one scheduler, and one memory manager with everything else on the host. That single fact explains both the appeal and the limits of the technique. A container starts in a fraction of a second and wastes almost no memory on a second kernel, but a container is only as isolated as the namespaces, cgroups, and capability masks that define it, and a kernel compromise is a host compromise.

This chapter runs real workloads on real Debian 13 hosts rather than surveying the field. It builds a rootless web service with Podman, wires it into systemd so it survives reboots, feeds it persistent data and secrets, and publishes its image to a private registry so a second host can deploy the exact same bytes by digest. It then repeats the exercise with Docker Compose, boots a full Debian userspace in a systemd-nspawn system container, and finishes by troubleshooting the failure modes that container operators actually meet: permission denials from UID mapping, port and firewall conflicts, resource exhaustion, and containers that ask for more privilege than they need.

The practice machines and their addresses:

Host Role Practice interface Administration
ctr1 container host: rootless user services, rootful private registry, Compose stack, system container eth1 - 192.168.245.10/24 eth0 - management network, 192.168.121.0/24
ctrclient independent client with its own rootless Podman store eth1 - 192.168.245.20/24 eth0 - management network

The chapter 25 practice hosts and container services

Figure 25.1. Two Debian 13 guests. Management SSH arrives over eth0; the exercises use the isolated 192.168.245.0/24 link. The registry, the rootless service, the Compose stack, and the system container all live on ctr1, while ctrclient keeps a separate Podman store and pulls the published images from outside.

The management network carries every administrative SSH session, so a mistaken firewall or port change on the practice network cannot lock you out of the hosts. The lab interfaces are static; configure them with the tools of Chapter 17, which also covers the name resolution this chapter assumes. Both hosts must resolve the registry name to its lab address before the registry exercises; the practice guests keep the mapping in /etc/hosts, which on both hosts as root looks like:

192.168.245.10 registry.ctr1.lab

The file produces no output when written; a production site would publish the same record through DNS as described in Chapter 22 instead.

Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker itself is not typed. A single elevated step is written $ sudo command, which asks for john's password the first time in a session. Sustained administrative work can open a root shell with $ sudo -i, whose prompt is #, and exit leaves it. john obtains these rights through the sudo policy of Chapter 5; adapt the elevated commands if your site delegates administration differently. Before each block the text names the host and account. The examples run as john on both hosts; the system-container work in Section 25.7 runs as root because machine management is a host-level operation.

Example files live under a named workspace in john's home. On both ctr1 and ctrclient, as john:

$ mkdir -p ~/debian-handbook/containers

The command prints nothing on success. Unless a step changes directory, commands on ctr1 run from ~/debian-handbook/containers. After sudo -i, ~ is /root, not john's home, so elevated steps spell the workspace path out in full.

The Debian 13 packages in this chapter are the current archive versions. Check them on your own host before relying on a particular option; Podman's Quadlet interface and Compose providers both evolve between major releases, and behavior described here is tied to the versions shown in Section 25.2.1.

In this section