Sub topic 12
Exposing ports below 1024
This chapter assumes you have a working rootless daemon, a configured client, and a basic grasp of Linux users and the sysctl command. You should also know how docker run -p publishes a port.
Why low ports fail
On Linux, only privileged processes may bind to ports 1 to 1023 by default. The kernel enforces this through net.ipv4.ip_unprivileged_port_start, which defaults to 1024.
A rootless daemon runs as your unprivileged user. When you publish a port, the daemon's port forwarder binds that port in the host's network namespace. Ports above 1023 work without extra setup. Ports below 1024 fail:
docker run -d --name web80 -p 80:80 nginxThe command fails with an error saying the daemon cannot bind to 0.0.0.0:80 because permission was denied. The container is not created, or it is created but never starts, depending on the Docker version.
Option 1: Lower the unprivileged port start
The simplest fix is to lower the kernel threshold. This example allows any user to bind ports from 80 upward:
# 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 --systemVerify the value, then retry:
sysctl net.ipv4.ip_unprivileged_port_start
docker run -d --name web80 -p 80:80 nginx
curl -I http://localhost:80Option 2: Publish a high port and redirect
If you cannot change kernel settings, publish a port above 1023 and put something with privileges in front of it. Examples include a root-owned reverse proxy, a firewall rule that redirects port 80 to 8080, or a load balancer. This keeps the daemon unprivileged and moves the privilege to a small, well-understood component.
docker run -d --name web -p 8080:80 nginxChoosing between the options
| Approach | Needs root on the host | Scope of change | Best for |
|---|---|---|---|
| Lower `ip_unprivileged_port_start` | Yes, once | Whole host, all users | Single-user machines and dev boxes |
| Publish a high port and redirect | Yes, for the redirect or proxy | One service | Shared hosts and production |
Common errors
- Permission denied after editing the file. The file takes effect only after
sudo sysctl --systemruns, or after a reboot. Check the live value withsysctl. - The value resets after a reboot. Make sure the file is under
/etc/sysctl.d/and ends in.conf. - The port binds, but connections come from the wrong address. Rootless networking can hide the original client address, because traffic passes through the RootlessKit port driver. Do not rely on the source IP inside the container for access control.
- The port is already in use. Another service, such as a system web server, holds it. Run
ss -ltnpto find it.
Exercise
A teammate sets net.ipv4.ip_unprivileged_port_start=0 so that their rootless containers can publish ports 80 and 443. The machine is shared with other developers. Why is this a poor choice, and what is a safer alternative?
Show answer
The setting is host-wide, so every local user and process can bind any port, including ports for well-known services such as 22 or 443. Another user could run a fake service on them. A safer choice is to set the threshold only as low as needed (for example 80), or to publish high ports such as 8080 and 8443 and use a root-owned reverse proxy or firewall redirect for 80 and 443.
Exercise
After running sudo sysctl --system, docker run -p 80:80 nginx still fails with permission denied, but sysctl net.ipv4.ip_unprivileged_port_start prints 80. What should you check next?
Show answer
Check whether the error is a bind conflict instead of a permission problem, for example another process on port 80 (use ss -ltnp). Also confirm that the CLI talks to the rootless daemon (docker context show or echo $DOCKER_HOST), because a different daemon may be answering.