25.8. Troubleshooting and Containing Container Workloads
Container failures have a useful property: they are ordinary Linux failures with a namespace in front of them. The four families in this section - permission denials, network conflicts, resource exhaustion, and privilege overreach - cover most of what a container operator debugs, and each diagnosis starts from the same kernel mechanisms Section 25.1 introduced.
25.8.1. UID Mappings and Permission Denials
The most common rootless failure is a container that cannot read or write a host file, and the diagnosis always starts at the UID map. Re-read it in full - both halves, UID and GID. On ctr1, as john:
$ podman unshare cat /proc/self/uid_map; podman unshare cat /proc/self/gid_map
0 1001 1
1 100000 65536
65537 165536 65536
0 1001 1
1 100000 65536
65537 165536 65536
The two reports are identical here; they diverge when an account's subordinate UID and GID ranges differ, which is exactly the situation that produces "works as root's container, fails as mine" behavior. Now the failure itself. Mount a host file that only root can read into a rootless container and try to read it. On ctr1, as john:
$ podman run --rm -v /etc/shadow:/etc/shadow:ro docker.io/library/alpine:3.20 cat /etc/shadow
Trying to pull docker.io/library/alpine:3.20...
Getting image source signatures
Copying blob sha256:25f1d6b1951ac8eb3740558fe94cb83d377bdadf95fd9f98b50d2e1b96130471
Copying config sha256:bf8527eb54c3680e728d5b4b383a8ba730d72dae7236fbc8dff97ed6b224a731
Writing manifest to image destination
cat: can't open '/etc/shadow': Permission denied
The mount succeeded - the runtime can see the file - but the read
failed, because the container's "root" is host UID 1001, and /etc/shadow
is not readable by UID 1001. The user namespace did its job: mounting a
sensitive file into a rootless container does not hand it over. Contrast
the rootful path. On ctr1, entered by john:
$ sudo podman run --rm -v /etc/shadow:/etc/shadow:ro docker.io/library/alpine:3.20 sh -c 'wc -l /etc/shadow'
26 /etc/shadow
Rootful, the same mount gives the container's root host-root's authority,
and the file reads. That asymmetry is the design, not a bug: when a
rootless workload fails with Permission denied on a bind mount, check
the file's host ownership against the UID map before changing anything
else. The remedies follow directly from the map:
- Give the invoking user access to the host path (ownership or group permissions, per Chapter 5).
- Let the container write as the user it already is: Section 25.3.2 showed that a rootless container's writes land in john's ownership by default.
- Match UIDs deliberately with
--userns=keep-idwhen the container must run as a specific UID - orpodman unshare chownfrom the host side to map ownership into the subordinate range for volumes the container's internal UID must own. - Reserve the rootful runtime for mounts that genuinely require host root's reach, and treat each one as a privilege decision.
25.8.2. DNS, Port Publishing, and Firewall Conflicts
Name resolution failures inside a container network are almost always
aardvark's to fix or to report. Containers on a user-defined network
resolve each other through the DNS service that netavark runs beside the
network (Section 25.3.1 showed netapp.dns.podman answering). When a
name does not resolve from a container that should reach it, check the
two halves separately: podman network inspect NAME shows whether the
network exists and which subnet and DNS state it has, and a
getent hosts <name> from a container on that network asks the question
directly. A name that resolves but does not answer is then a connectivity
problem, not DNS.
Port publishing conflicts announce themselves at the bind. The service
from Section 25.4 already holds 192.168.245.10:8080; a second publisher
on the same address and port cannot succeed. On ctr1, as john:
$ podman run --rm -p 192.168.245.10:8080:8080 docker.io/library/alpine:3.20 true
Error: pasta failed with exit code 1:
Failed to bind port 8080 (Address already in use) for option '-t 192.168.245.10/8080-8080:8080-8080'
The error names the bind, the address, and the port - Address already in
use - before anything started. ss -ltnp on the host
(Chapter 17) identifies the current
holder; the remedy is a different port or address, not a retry. Rootless
publishing fails at bind time like this precisely because pasta binds a
real socket as the user.
Rootful publishing fails later and more subtly, because it works through the host's forwarded-packet path, where other rule managers live. The following exercise needs the Docker daemon from Section 25.5 running on the same host. Start a rootful container publishing a port. On ctr1, as root:
# podman run -d --name forwardtest -p 192.168.245.10:5002:80 docker.io/library/nginx:1.27-alpine
d65c2f923eb14f70361b79af040ba7e4370165fd7670860aed86f33c5f67a2ff
The run prints the container ID. If this is the rootful store's first copy of the image, the pull's progress lines precede the ID, exactly as in the rootless pulls of Section 25.2.2. The container is up and its port forward rule exists - but the client gets silence. On ctrclient, as john:
$ curl -sS --max-time 5 http://192.168.245.10:5002/
curl: (28) Connection timed out after 5002 milliseconds
A published port that times out rather than refusing is a forwarding path problem: the packet arrived and was dropped somewhere between the host's ingress and the container. On this host, the somewhere is the FORWARD chain, which more than one component manages. On ctr1, as root:
# nft list chain ip filter FORWARD | head -3
table ip filter {
chain FORWARD {
type filter hook forward priority filter; policy drop;
head -3 bounds the listing to the table and chain headers plus the
policy line. The ip filter table is the
legacy iptables view - the warning table ip filter is managed by
iptables-nft appears on stderr when listing it - and its FORWARD policy
is drop, set by Docker's daemon when it installed its own rules. Only
packets matching Docker's own accept rules pass; the rule netavark added
for forwardtest lives in a different chain, so forwarded packets to the
container hit the drop policy first. Two runtimes, one hook, and the
last installer wins.
The remedies, in order of preference: keep one runtime's rootful port
publishing on a host, or publish rootless, whose pasta path bypasses the
forwarded-packet machinery entirely (the lab's own service runs this
way); or manage the interaction explicitly, adding accept rules for the
netavark chains in the host's own nftables policy as
Chapter 18 describes for container and virtualization
interactions. Docker's published Compose port on this same host worked
because Docker's rules and Docker's containers agree with each other.
Clean up the exercise with podman rm -f forwardtest.
25.8.3. Resource Exhaustion and Unexpected Container Exits
A memory limit turns a leak into an event rather than an outage. The following container asks for far more memory than its limit allows. On ctr1, as john:
$ podman run --rm --memory=32m docker.io/library/alpine:3.20 sh -c 'dd if=/dev/zero of=/dev/shm/fill bs=1M count=128'
The command produces no output: dd never finished, because the cgroup's
memory limit was exceeded and the kernel's OOM killer terminated the
container's process. The command's exit status is 137 - 128 plus signal
9, SIGKILL, delivered by the kernel's OOM logic against the
container's cgroup. This is the intended outcome of a memory limit under
abuse: the container dies, the host does not. The same mechanism with a
higher limit is what PodmanArgs=--memory=128m buys the service in
Section 25.4.3. When a container exits 137 under a limit, the
investigation is a memory leak or an undersized limit - compare the
container's actual usage (podman stats) against the limit, and read the
OOM event in the journal, which records the kill the same way it does for
any cgroup on the host (Chapter 9).
Unexpected exits without a limit are diagnosed from the container's own state, and the restart policy decides whether you get to see them. Run a container that always fails, with a bounded restart policy. On ctr1, as john:
$ podman run -d --name flaky --restart=on-failure:2 docker.io/library/alpine:3.20 sh -c 'exit 7'
56518d1048493c045e543ea3ff986c968ffdddb85cb8671abe342f5b41a41326
The run prints the container ID. Give the policy time to work, then read what the runtime recorded. On ctr1, as john:
$ podman inspect --format '{{.State.ExitCode}} {{.RestartCount}} {{.State.Status}}' flaky
7 2 exited
Three fields, three facts: the process exited with code 7 (the
application's own failure), the runtime restarted it twice (the policy's
limit), and the container is now exited - the runtime gave up as told.
on-failure:N is the policy for a service that should retry transient
failures but must not spin forever; a Quadlet unit adds systemd's
Restart= on top, so the unit can also bound and report the loop
(Chapter 8 covers start-rate limiting). Clean up
with podman rm -f flaky.
The general exit-code vocabulary is short: 137 is an OOM kill or an
explicit SIGKILL; 126 and 127 are execution failures (permission
denied, command not found); anything else is the application's own
numbering, to be read from its logs - podman logs when the image writes
to standard streams, the journal when it runs under a unit. A health
check (Section 25.4.3) catches the subtler case where the process runs
but the service is broken.
25.8.4. Reducing Capabilities and Avoiding Privileged Containers
The capability masks from Section 25.1.1 are the containment dial, and the three observed settings make the range concrete:
| Setting | Observed CapEff |
Meaning |
|---|---|---|
| default rootless | 00000000800405fb |
a dozen capabilities: CHOWN, SETUID, NET_BIND_SERVICE, SYS_CHROOT, and peers |
--cap-drop=ALL |
0000000000000000 |
none; the process survives on file permissions alone |
--privileged |
000001ffffffffff |
every capability the kernel offers, plus relaxed isolation limits |
The direction of travel should always be rightward in intent but never
past what the workload needs: drop everything, then add back the one
capability the application actually uses. A static site needs nothing -
the --cap-drop=ALL row is a working configuration for it, given a
non-root USER and the file permissions the image already sets. A
service that must bind a low port legitimately needs
--cap-add=NET_BIND_SERVICE, and nothing else changes. --privileged
exists for a narrow class of work - some device passthrough and nested
container building - and in exchange it removes nearly every boundary
this chapter has relied on: all capabilities, and the runtime's other
containment defaults.
Look at what --privileged actually grants before ever typing it. On
ctr1, as john:
$ podman run --rm --privileged docker.io/library/alpine:3.20 grep CapEff /proc/self/status
CapEff: 000001ffffffffff
Under rootless Podman the user namespace still bounds the damage - container root remains host-john - but rootful and privileged together is a container that can reconfigure the host, and Section 25.8.2's firewall conflict shows how easily two components on one host can mislead each other even without malice. The containment checklist that follows from this chapter's exercises, in the order worth applying:
- Run rootless (Section 25.1.3); escalate to rootful only for a named host-level need.
- Run as a non-root
USERinside the image (Section 25.2.4). - Drop all capabilities and add back the minimum (this section).
- Make the root filesystem read-only, with explicit writable paths (Section 25.3.3).
- Mount secrets rather than baking or exporting them (Section 25.3.3).
- Cap memory and CPU through the unit that owns the container (Section 25.4.3).
Each step is independent, each is one line in a Quadlet unit or a Containerfile, and together they reduce a container to the smallest privilege that still does its work - the same least-privilege posture Chapter 26 applies to native services through AppArmor and systemd sandboxing.