Sub topic 11
Networking and publishing ports without root
This chapter assumes you have a working rootless daemon, a client connected to it, and basic Docker networking knowledge (bridge networks, -p). It covers how rootless networking differs from rootful networking and how to publish ports.
Why networking is different
A rootful daemon creates virtual network interfaces and edits iptables rules on the host. An unprivileged user cannot do either. Rootless Docker therefore runs the daemon and its containers in a separate network namespace. RootlessKit, the helper that starts the daemon, connects that namespace to the host with a user-space network stack (usually slirp4netns, or pasta in newer setups).
Traffic from a container takes this path:
- The container sends packets to the bridge inside the namespace.
- The user-space stack converts them into ordinary socket calls made by your user.
- The host sees those calls as coming from a normal process, not from a container.
Publishing ports
The -p flag works as usual. The RootlessKit port driver listens on the host port and forwards connections into the namespace.
docker run -d --name web -p 8080:80 nginx
curl -I http://localhost:8080Ports above 1023 need no extra setup.
Source IP addresses and performance
Two side effects follow from the user-space stack:
- Throughput is lower. Every packet crosses the user-space layer, so expect less bandwidth than with rootful Docker.
- Source addresses may be hidden. With the default port driver, a container may see connections as coming from an internal address instead of the real client IP. Newer Docker releases use the
builtinport driver, which preserves the source address in most cases. If your application logs client IPs, check what it actually receives.
Containers can still reach the internet and each other over user-defined networks. Name-based discovery on those networks works as it does in rootful mode.
Ports below 1024
Linux blocks unprivileged processes from binding ports 1 to 1023. Publishing -p 80:80 fails with a permission error. The simplest fix is to lower the system-wide threshold.
# Allow unprivileged processes to bind ports from 80 upward
echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/99-rootless-ports.conf
sudo sysctl --systemCommon errors
| Symptom | Likely cause |
|---|---|
| `permission denied` when publishing port 80 | `ip_unprivileged_port_start` is still 1024 |
| Port is published but unreachable from other machines | Host firewall blocks it, or the service listens only on localhost |
| Application logs show the same client IP for everyone | The port driver replaces the source address |
| `ping` fails inside a container | The group ID range in `net.ipv4.ping_group_range` does not include your user |
Exercise
You run docker run -d -p 443:443 nginx with a rootless daemon and get a permission error. Name two ways to make the service reachable, and one downside of the first.
Show answer
Lower net.ipv4.ip_unprivileged_port_start to 443 or below, or publish a high port such as 8443 and redirect or proxy 443 to it. The downside of lowering the sysctl is that it applies to every user and process on the host, so any unprivileged program can then bind those ports.
Exercise
Why does a rootless daemon use a user-space network stack instead of creating bridge interfaces on the host?
Show answer
Creating network interfaces and iptables rules on the host needs root privileges. An unprivileged user cannot do either, so the daemon uses a separate network namespace and a user-space stack to pass traffic to the host.