This guide shows Linux administrators how to switch a server to Docker rootless mode, where the Docker daemon (the background service that runs containers) runs as an ordinary user instead of root. Adding someone to the docker group quietly gives them root on the host, because that daemon runs as root and will mount / into a container whenever asked. Rootless mode fixes this and keeps the same docker CLI (command-line tool), images and Compose files. The difference is that dockerd runs inside a user namespace, a Linux feature that maps root inside the container to your own unprivileged account. By the end, the daemon will start at boot, containers will publish ports, memory and CPU limits will work, and you will have a clear list of the workloads that cannot make the move.
What you’ll accomplish
- A
dockerdprocess running as an unprivileged user, with its socket at$XDG_RUNTIME_DIR/docker.sockand its data under~/.local/share/docker. - Nobody in the
dockergroup, and no need forsudoto run containers. - A user systemd unit that starts the daemon at boot and keeps it alive after the operator logs out.
- Working
--memoryand--cpuslimits through delegated cgroup v2 controllers. - A deliberate decision about ports below 1024, and a documented list of what this host can no longer do.
Prerequisites
- A Linux host with kernel 5.11 or newer if you want the native
overlay2storage driver in rootless mode. Older kernels fall back tofuse-overlayfs, which works but is slower; without either, Docker drops to thevfsdriver, which copies every layer and eats disk. - cgroup v2 mounted as the unified hierarchy, plus systemd. Without it, resource limits silently do nothing. Ubuntu 22.04+, Debian 11+, Fedora 31+ and RHEL 9 are cgroup v2 by default; RHEL 8 and CentOS 8 are not, unless you booted with
systemd.unified_cgroup_hierarchy=1. - Docker Engine 20.10 or newer installed from Docker’s own repository. The rootless helper scripts ship in a separate package,
docker-ce-rootless-extras, which the distribution-packageddocker.ioon Debian and Ubuntu does not carry. If you installed from the distro repo, redo it from Docker’s install instructions first. newuidmapandnewgidmapfrom theuidmappackage on Debian and Ubuntu, orshadow-utilson RHEL, Rocky and AlmaLinux. These are setuid or file-capability binaries; without them a normal user cannot write a multi-entry UID map.- A subordinate ID range of at least 65,536 for the account, in
/etc/subuidand/etc/subgid. - On Debian and Ubuntu,
dbus-user-session, otherwisesystemctl --userfails over SSH. - On Ubuntu 24.04 and newer, unprivileged user namespaces are restricted by AppArmor. The
docker-ce-rootless-extraspackage installs the RootlessKit profile that makes it work; if you install by hand, expect to write that profile yourself. - One account that will own the daemon. This guide uses
deploywith UID 1000.
How it works
Rootful Docker has no privilege boundary between the client and the host. The socket is group-writable, the daemon behind it is UID 0, and container UID 0 is host UID 0. Rootless mode inserts a user namespace between the two.
RootlessKit creates the namespace and starts dockerd inside it. The UID map it installs has two entries: container UID 0 maps to your own host UID, and container UIDs 1 through 65536 map into your subordinate range starting at 100000. So a file written by container root shows up on the host owned by deploy, and a file written by container UID 1000 shows up owned by host UID 100999. Everything the daemon and its containers can touch is bounded by what deploy could already touch.
Networking is the part that changes most. Inside the namespace there is no permission to create a veth pair on the host bridge, so RootlessKit runs a TCP/IP stack in user space — slirp4netns by default, or pasta on newer builds — and forwards published ports from the host side into the container namespace.
Step-by-step
-
Check the host before you install anything. These four probes cover the usual reasons a first attempt fails.
uname -r stat -fc %T /sys/fs/cgroup/ grep "^$(id -un):" /etc/subuid /etc/subgid command -v newuidmap newgidmapExpected: a kernel version, the literal string
cgroup2fs, one line per file showing your range, and two paths under/usr/bin. Ifstatprintstmpfsyou are on cgroup v1 and resource limits will not work. If thegrepprints nothing, fix it in step 3. -
Install the helper packages. On Debian and Ubuntu:
sudo apt-get update sudo apt-get install -y uidmap dbus-user-session slirp4netns docker-ce-rootless-extrasOn RHEL, Rocky and AlmaLinux:
sudo dnf install -y shadow-utils fuse-overlayfs iptables docker-ce-rootless-extrasExpected:
dockerd-rootless-setuptool.shandrootlesskitnow resolve onPATH. Confirm withcommand -v dockerd-rootless-setuptool.sh rootlesskit, which should print two/usr/binpaths. -
Give the account a subordinate ID range, if it does not have one. Accounts created before the range defaults existed often have none.
sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 deploy grep "^deploy:" /etc/subuid /etc/subgidExpected:
/etc/subuid:deploy:100000:65536 /etc/subgid:deploy:100000:65536Ranges must not overlap between accounts on the same host. Two users sharing 100000 can read each other’s container filesystems, which quietly undoes the isolation you are here for.
-
Stop the rootful daemon. Not strictly required — both can coexist — but on a host whose whole point is that nobody gets root through Docker, leaving the privileged socket in place defeats the exercise.
sudo systemctl disable --now docker.service docker.socket sudo rm -f /var/run/docker.sockExpected:
systemctl is-active dockerprintsinactive, andls /var/run/docker.sockprints a “No such file or directory” error. -
Run the setup tool as the unprivileged user. Do not use
sudohere. That is the whole point, and the script refuses to run as root anyway.dockerd-rootless-setuptool.sh installExpected: a run of
[INFO]lines ending with something close to this.[INFO] Creating /home/deploy/.config/systemd/user/docker.service [INFO] starting systemd service docker.service [INFO] Installed docker.service successfully. [INFO] To control docker.service, run: `systemctl --user (start|stop|restart) docker.service` [INFO] To run docker.service on system startup, run: `sudo loginctl enable-linger deploy` [INFO] Creating CLI context "rootless" [INFO] Use CLI context "rootless" Current context is now "rootless"If it stops early with a
[ERROR]line naming a missing binary or a missing subuid range, go back to step 2 or 3 — the script’s owndockerd-rootless-setuptool.sh checksubcommand runs the same pre-flight without installing anything. -
Point the client at the rootless socket. Recent versions create and select a CLI context for you. Older ones expect an environment variable, and any existing
DOCKER_HOSTin a shell profile will override the context, so set one deliberately.docker context use rootless echo 'export DOCKER_HOST=unix://'"$XDG_RUNTIME_DIR"'/docker.sock' >> ~/.bashrc docker context lsExpected: the
rootlessrow carries an asterisk and the endpointunix:///run/user/1000/docker.sock. -
Enable linger so the daemon outlives your session. Without this, systemd tears down the user manager at logout and every container dies with it.
sudo loginctl enable-linger deploy loginctl show-user deploy --property=LingerExpected:
Linger=yes. Then make the unit start on boot:systemctl --user enable --now docker systemctl --user is-enabled dockerExpected:
enabled. -
Delegate cgroup controllers so resource limits work. By default systemd only delegates a subset to user sessions, and
--memoryor--cpuswill be discarded with a warning.sudo mkdir -p /etc/systemd/system/user@.service.d printf '[Service]\nDelegate=cpu cpuset io memory pids\n' | sudo tee /etc/systemd/system/user@.service.d/delegate.conf sudo systemctl daemon-reloadLog out and back in, then confirm the controllers arrived:
cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllersExpected:
cpuset cpu io memory pids. -
Decide about ports below 1024. Rootless containers cannot publish port 80 or 443 by default, and this is the step teams most often discover during a launch instead of during setup.
The tidiest answer is usually not to fight it: publish on 8080 and let a system-level reverse proxy or a load balancer own 80 and 443. If the container really must bind low, lower the boundary on the host:
echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/99-rootless-ports.conf sudo sysctl --system sysctl net.ipv4.ip_unprivileged_port_startExpected:
net.ipv4.ip_unprivileged_port_start = 80. The narrower alternative grants the capability to the forwarder only:sudo setcap cap_net_bind_service=ep "$(command -v rootlesskit)" getcap "$(command -v rootlesskit)"Expected: a line ending in
cap_net_bind_service=ep. Restart the daemon afterwards withsystemctl --user restart docker.
Validate it works
First, confirm the daemon reports rootless mode and is storing data in your home directory:
docker info 2>/dev/null | grep -E 'Storage Driver|Cgroup Version|Docker Root Dir|rootless'
Expected, roughly:
Storage Driver: overlay2
Cgroup Version: 2
Docker Root Dir: /home/deploy/.local/share/docker
rootless
Second, confirm the process is not root:
ps -o user= -p "$(pgrep -x dockerd | head -1)"
Expected: deploy. If this prints root, your client is talking to a rootful daemon somewhere — check DOCKER_HOST and docker context ls.
Third, read the UID map the namespace is actually using:
cat /proc/"$(pgrep -x dockerd | head -1)"/uid_map
Expected:
0 1000 1
1 100000 65536
Fourth, prove the mapping end to end with a file:
mkdir -p ~/probe
docker run --rm -v ~/probe:/data alpine sh -c 'id -u; touch /data/as-root'
docker run --rm --user 1000:1000 -v ~/probe:/data alpine touch /data/as-user
ls -n ~/probe
Expected: 0 from id -u inside the container, then two files on the host — as-root owned by UID 1000, and as-user owned by UID 100999. That second number is the proof: container UID 1000 landed on a host UID that exists nowhere in /etc/passwd and owns nothing.
Finally, check that limits are enforced rather than ignored:
docker run --rm --memory 128m alpine cat /sys/fs/cgroup/memory.max
Expected: 134217728. If it prints max, revisit step 8.
Troubleshooting
No subuid ranges found for user. RootlessKit refuses to start because /etc/subuid has no entry for the account. Add one with usermod --add-subuids as in step 3, then systemctl --user restart docker. The same message appears when the range is smaller than 65,536.
The setup tool exits complaining about newuidmap. The uidmap package (or shadow-utils) is missing, or the binary lost its file capabilities. Check with getcap /usr/bin/newuidmap, which should print cap_setuid=ep. A reinstall of the package restores it. Some hardening scripts strip setuid and capability bits across /usr/bin and break rootless mode as a side effect.
Everything dies when the operator logs out. Linger is not enabled. loginctl show-user deploy --property=Linger returns Linger=no. Run sudo loginctl enable-linger deploy. Related: systemctl --user over SSH failing with Failed to connect to bus means dbus-user-session is not installed, or XDG_RUNTIME_DIR is unset in a non-login shell.
bind: permission denied publishing port 80. Expected behaviour, not a bug. Publish high and reverse-proxy, or apply one of the two changes in step 9.
--memory and --cpus are ignored, and docker info prints warnings about missing cpu or cpuset support. Either the host is on cgroup v1, or the controllers were never delegated to the user manager. stat -fc %T /sys/fs/cgroup/ tells you which. cgroup v1 has no fix short of a reboot into the unified hierarchy.
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock. The client is aimed at the rootful socket. DOCKER_HOST beats the CLI context, so unset DOCKER_HOST first, then docker context use rootless. Check root-owned shell profiles and CI runner environments too — that variable is often set somewhere nobody remembers.
When this is the wrong approach
Rootless mode buys a real privilege boundary and charges for it. Be clear about the bill before you commit a fleet.
The user-space network stack costs throughput. For a build agent or an internal API this is invisible; for a high-volume ingress proxy or anything moving large files, benchmark it first. Switching the port driver from builtin to slirp4netns restores the client source IP that containers otherwise see as 127.0.0.1, but costs more performance still — and applications that log or rate-limit by client IP care about this.
Some things simply do not work. Overlay networks and Swarm mode are out. Genuine host networking is out — --network host puts the container in RootlessKit’s namespace, not the host’s. Exposing SCTP ports, AppArmor confinement of containers, and checkpoint or restore are all unavailable. NFS-backed volumes generally will not mount from inside the namespace. If your workload needs any of that, rootless is not a configuration away from working.
If the aim is simply “no daemon running as root”, Podman gets there with no daemon at all, and its systemd integration through Quadlet is more natural for long-running services. Podman rootless mode explained in depth covers the same namespace mechanics, and installing Podman rootless is the shorter path if you are not already tied to Docker’s tooling and Compose files. The honest comparison: Docker rootless is the low-friction option when a team already runs Docker and wants the group membership gone; Podman is the better fit when you are choosing fresh.
Finally, rootless is not the only answer to “developers must not have host root”. A dedicated rootful build host that no human logs into, driven only by a CI system, with a remote API secured by mutual TLS, is a defensible design too. Rootless mode is what you want when people share a machine. Read Docker’s own rootless mode documentation for the current limitation list before you standardise on it, because that list gets shorter with each release.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.