Back to Blog
App DevelopmentPublished on October 23, 2026

Docker Is Weird: Deconstructing iptables Bypasses, Zombie Reaping, and OverlayFS Quirks

Docker's abstraction over Linux kernel primitives often produces unexpected runtime behaviors that baffle senior engineers. We deconstruct the mechanics behind silent firewall bypasses, PID 1 signal swallowing, and OverlayFS whiteout dynamics.

The Illusion of Isolation: Why Containers Defy Developer Mental Models

Software engineers often treat Docker containers as lightweight virtual machines. We assign them IP addresses, expose ports, configure volume mounts, and expect them to behave as isolated operating systems. However, containers do not exist as concrete hardware entities inside the Linux kernel. A container is merely an ordinary host process constrained by an aggregation of kernel primitives: control groups (cgroups), Linux namespaces (pid, net, mnt, ipc, uts, user), security profiles (seccomp, AppArmor), and union filesystems.

Because Docker shares the host kernel directly rather than emulating a hardware abstraction layer via a hypervisor, the boundaries between the containerized application and the host operating system are notoriously porous. When these kernel features interact in non-intuitive ways, Docker behaves in ways that seem outright bizarre to developers accustomed to traditional OS behavior.

From silently exposing sensitive database ports directly to the public internet despite local firewall rules, to node processes refusing to terminate upon receiving SIGTERM, to mysterious inode exhaustion on disks with gigabytes of free space—understanding Docker requires looking beneath the CLI syntax into the Linux kernel internals.


The Firewall Illusion: Why Docker Silently Bypasses ufw and iptables

One of the most catastrophic surprises engineers face in production is Docker's interaction with host firewalls like Uncomplicated Firewall (ufw) or standard iptables configurations. A developer will configure ufw default deny incoming, allow only port 80 and 443, spin up a PostgreSQL container using -p 5432:5432, and assume that the database is shielded from the public internet. Within minutes, automated scanners are brute-forcing the database on the open web.

The Netfilter PREROUTING Trap

To understand why this occurs, we must trace how Netfilter routes network packets through the kernel's routing tables. The standard packet lifecycle follows distinct chains: PREROUTING, INPUT, FORWARD, OUTPUT, and POSTROUTING.

When a firewall like ufw is enabled, it installs its defensive rules primarily into the INPUT chain. Packets destined for processes listening on the local host system (like an SSH daemon) pass through PREROUTING and enter INPUT, where ufw blocks or permits them.

However, Docker does not bind exposed container ports like a traditional host daemon. Instead, Docker establishes Network Address Translation (NAT) rules to route traffic across the docker0 bridge into the container's isolated network namespace (netns). To achieve this, the Docker daemon modifies the Netfilter nat table directly, injecting rules into the PREROUTING chain:

# Inspecting the nat table reveals Docker's direct routing hook
sudo iptables -t nat -L PREROUTING -n -v

# Output:
# Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
#  pkts bytes target     prot opt in     out     source      destination         
#  124K 7440K DOCKER     all  --  *      *       0.0.0.0/0   0.0.0.0/0   ADDRTYPE match dst-type LOCAL

Because Destination NAT (DNAT) rewrites the destination IP of the packet to the container's private IP inside the bridge network before the packet reaches the local routing decision, the kernel determines that the packet is not destined for the local host, but rather needs to be routed to another network interface (veth*).

Consequently, the packet completely bypasses the INPUT chain—and with it, every single rule configured in ufw. The packet is shunted directly to the FORWARD chain. Since Docker installs an ACCEPT rule in the FORWARD chain for established container endpoints, the firewall is completely circumvented.

The Architectural Remediation

Disabling Docker's Netfilter manipulation by setting {"iptables": false} in /etc/docker/daemon.json seems like the obvious fix, but it severely impairs container networking, disabling outbound internet access for containers unless manual SNAT masquerading is configured.

The robust solution requires hooking into the DOCKER-USER chain. Docker guarantees that rules placed in DOCKER-USER are evaluated before Docker's own forwarding rules in the FORWARD chain:

# Block all external access to container port 5432 on eth0
iptables -I DOCKER-USER -i eth0 -p tcp --dport 5432 -j DROP

# Allow access only from a trusted administrative subnet
iptables -I DOCKER-USER -i eth0 -s 192.168.1.0/24 -p tcp --dport 5432 -j ACCEPT

The PID 1 Trap: Signal Propagation and the Zombie Apocalypse

Another common symptom of Docker's "weirdness" occurs during deployment shutdowns: containers take exactly 10 seconds to stop, and child processes spawn continuously until the system freezes. This behavior stems from the unique semantics of Process ID 1 (PID 1) in Unix-like systems.

Why Node.js, Python, and Java Ignore SIGTERM

In standard Linux execution, PID 1 is assigned to the init system (such as systemd or SysVinit). The kernel treats PID 1 fundamentally differently than every other process in the tree:

  1. Signal Immunization: For any process other than PID 1, if a signal (such as SIGTERM or SIGINT) does not have an explicit signal handler registered, the kernel terminates the process using the default action. However, for PID 1, the kernel will not apply default signal actions. If the process does not explicitly install a custom handler for SIGTERM, the signal is dropped silently by the kernel.
  2. Orphan Reaping: When any process forks a child and terminates before that child, the child becomes an orphan. The Linux kernel reparents that orphaned process to PID 1. PID 1 is contractually obligated to run an event loop calling wait() or waitpid() to collect the exit status of terminated children. If PID 1 fails to do this, dead processes remain in the process table indefinitely as zombies ([defunct]).

When you run a container with ENTRYPOINT ["node", "app.js"] or CMD ["python", "main.py"], that application runtime becomes PID 1 inside the container's PID namespace. Most language runtimes do not install native signal handlers for SIGTERM by default because they assume an init system or shell is managing them.

When Docker executes docker stop <container>, it sends SIGTERM to PID 1. The runtime ignores it. Docker waits for a default grace period of 10 seconds, gives up, and executes SIGKILL (which cannot be caught or ignored), abruptly severing open TCP connections, leaving files corrupted, and breaking graceful connection draining.

The Shell Wrapper Anti-Pattern

This problem is frequently exacerbated by executing commands in shell form within Dockerfiles:

# BROKEN: Executes /bin/sh -c "node server.js"
CMD node server.js

Using shell form causes /bin/sh to run as PID 1, with node running as a child process (PID 2). Standard /bin/sh does not forward incoming signals to child processes. The SIGTERM hits /bin/sh, which does not forward it to node. Ten seconds later, the container is forcibly obliterated with SIGKILL.

Architectural Remediation: Lightweight Init Systems

To restore standard Unix process semantics, containers should leverage a minimal init process whose sole responsibilities are signal forwarding and zombie reaping:

  • Docker Native Flag: Run containers with the --init flag, which mounts a tiny, purpose-built init daemon (tini) as PID 1:
    docker run --init -d my-node-app:latest
    
  • Embedded Tini in Dockerfile: For production Kubernetes environments where CLI flags are abstracted, embed tini directly into your final layer:
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]
CMD ["node", "server.js"]

tini accepts signals from the host kernel, propagates them to the process group, and continually reaps zombie processes via an asynchronous waitpid(-1, &status, WNOHANG) loop.


Storage Layer Sorcery: OverlayFS, Inodes, and Whiteout Files

Docker images are built upon Union Filesystems, most commonly OverlayFS (overlay2 driver). OverlayFS layers directories on top of each other and presents them as a single unified view. While this allows fast container boot times and minimal storage duplication, it introduces anomalies that routinely confuse developers.

  +-------------------------------------------------------+
  |                      Merged View                      |
  |           /app/config.json (Read-Write)               |
  +-------------------------------------------------------+
                             |                             
         +-------------------+-------------------+
         |                                       |
         v                                       v
  +--------------+                       +---------------+
  |   Upperdir   |                       |   Lowerdirs   |
  | (Container   |                       | (Image Layers |
  |  Read-Write) |                       |  Read-Only)   |
  +--------------+                       +---------------+

The Cost of Copy-Up

OverlayFS distinguishes between lowerdir (the read-only image layers) and upperdir (the container's read-write runtime layer). When a container attempts to modify an existing file that originated from an underlying image layer, OverlayFS executes a copy-up operation.

If a container opens a 4GB database file located in a lower layer in append mode (a+), OverlayFS must copy the entire 4GB file from lowerdir to upperdir before the first byte can be written. This causes unexpected I/O spikes, latency anomalies, and sudden disk exhaustion, even when the actual mutation was only a few kilobytes.

The Mystery of the Whiteout File

What happens when a container deletes a file that exists in an underlying read-only layer? Because it cannot mutate the read-only layer, OverlayFS creates a whiteout file in the upperdir.

A whiteout file is a special character device with major and minor device numbers set to 0/0 (mknod c 0 0). When the kernel merges the directory structures, the existence of this 0/0 character device in the upper layer instructs the kernel to mask and hide the identically named file in the lower layer.

# Inspecting an overlay container upperdir on the host:
ls -la /var/lib/docker/overlay2/<layer-id>/diff/etc/

# Output showing a whiteout character device:
# c--------- 1 root root 0, 0 Oct 24 10:14 resolv.conf

This mechanism explains why deleting files in subsequent Dockerfile steps does not reduce image size:

# ANTI-PATTERN: Results in an inflated image containing both the file
# and a whiteout device masking it
RUN wget https://example.com/huge-dataset.tar.gz && tar -xzf huge-dataset.tar.gz
RUN rm huge-dataset.tar.gz

The 1GB archive remains permanently trapped in the first layer; the second layer merely adds an invisible whiteout device on top of it. Multi-stage builds or single-layer cleanup operations (&& rm ...) are strictly required to avoid this layer bloat.


Virtual Ethernet and the Mysterious MTU Mismatch

Container networking relies on Linux Virtual Ethernet (veth) pairs. Think of a veth pair as a bidirectional virtual wire: whatever enters one end immediately exits the other. One endpoint of the pair stays in the host network namespace attached to a bridge (like docker0), while the other end is moved into the container's isolated network namespace and renamed to eth0.

+----------------------- Host Network Namespace -----------------------+
|                                                                      |
|  Physical NIC (eth0) <---> docker0 Bridge <---> veth9a7bc4          |
|                                                      ^               |
+------------------------------------------------------|---------------+
                                                       | (veth pair)
+-------------------- Container Network Namespace -----|---------------+
|                                                      v               |
|                                                     eth0             |
+----------------------------------------------------------------------+

A notoriously difficult issue to debug in virtualized environments (such as Docker running inside AWS EC2, OpenStack, or nested VPN tunnels) is Maximum Transmission Unit (MTU) blackholing.

By default, Docker sets the MTU of docker0 and its veth interfaces to 1500 bytes (standard Ethernet frame size). However, if the underlying cloud infrastructure or VPN encapsulates traffic (e.g., VXLAN, Geneve, or WireGuard), the effective host interface MTU might be lower (e.g., 1450 or 1420 bytes to account for encapsulation headers).

When a container initiates an outbound TCP handshake, small packets (SYN, ACK) pass without issue. But when the remote server sends a large payload that maxes out the 1500-byte frame, the underlying host network interface drops the packet because it exceeds the physical MTU and has the DF (Don't Fragment) bit set. The container hangs indefinitely waiting for data, producing bizarre "connection established, but hangs on payload" errors.

To resolve this globally, enforce the host's actual MTU in /etc/docker/daemon.json:

{
  "mtu": 1420
}

Diagnostic Matrix: Docker Runtime Anomalies

To rapidly isolate these kernel-level container quirks in production, use this diagnostic matrix:

| Symptom | Root Cause | Verification Command | Permanent Fix | | :--- | :--- | :--- | :--- | | Container takes 10s to stop; ignores SIGTERM | Application runs as PID 1 without signal handler; PID 1 signal immunization | docker top <container> | Use --init flag or embed tini as ENTRYPOINT | | Port exposed via -p reachable despite ufw block | Docker installs DNAT rules in PREROUTING, bypassing INPUT chain | iptables -t nat -L -n -v | Place defensive rules in the DOCKER-USER chain | | Image size remains massive despite deleting files | OverlayFS masks deleted lower-layer files using whiteout devices (0/0) | docker history <image> | Combine download and removal into a single RUN layer | | Outbound HTTP requests hang after TLS handshake | MTU mismatch between docker0 (1500) and host encapsulation (e.g., VXLAN) | ip link show docker0 | Set explicit "mtu" in /etc/docker/daemon.json |

Conclusion: Mastering the Underlying Primitives

Docker is not inherently unstable or erratic, but it is fundamentally unconcerned with preserving virtual machine abstractions. It exposes the raw mechanics of the Linux kernel directly to system architects.

When you manipulate a container, you are manipulating kernel cgroups, iptables chains, namespace isolation switches, and overlay file systems. Once you peel back the syntactic sugar of the Docker CLI and treat containers as ordinary processes subject to standard Linux networking and process tree hierarchies, the "weirdness" disappears, replaced by deterministic, controllable systems engineering.

#Docker#Linux Kernel#DevOps#Networking#System Architecture