Skip to content

Run the Docker daemon rootless instead of adding people to the docker group

Learn how to run Docker rootless mode on a Linux server, so people can use containers without joining the docker group, which is the same as having root. The guide walks through the prerequisites, starting the daemon under a normal user account, and the features you give up.

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 dockerd process running as an unprivileged user, with its socket at $XDG_RUNTIME_DIR/docker.sock and its data under ~/.local/share/docker.
  • Nobody in the docker group, and no need for sudo to run containers.
  • A user systemd unit that starts the daemon at boot and keeps it alive after the operator logs out.
  • Working --memory and --cpus limits 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 overlay2 storage driver in rootless mode. Older kernels fall back to fuse-overlayfs, which works but is slower; without either, Docker drops to the vfs driver, 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-packaged docker.io on Debian and Ubuntu does not carry. If you installed from the distro repo, redo it from Docker’s install instructions first.
  • newuidmap and newgidmap from the uidmap package on Debian and Ubuntu, or shadow-utils on 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/subuid and /etc/subgid.
  • On Debian and Ubuntu, dbus-user-session, otherwise systemctl --user fails over SSH.
  • On Ubuntu 24.04 and newer, unprivileged user namespaces are restricted by AppArmor. The docker-ce-rootless-extras package 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 deploy with 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.

Comparison of rootful Docker where the docker group grants host root, and rootless Docker where the daemon runs in a user namespace and container UID 0 maps to the operator's own UID

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

  1. 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 newgidmap

    Expected: a kernel version, the literal string cgroup2fs, one line per file showing your range, and two paths under /usr/bin. If stat prints tmpfs you are on cgroup v1 and resource limits will not work. If the grep prints nothing, fix it in step 3.

  2. 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-extras

    On RHEL, Rocky and AlmaLinux:

    sudo dnf install -y shadow-utils fuse-overlayfs iptables docker-ce-rootless-extras

    Expected: dockerd-rootless-setuptool.sh and rootlesskit now resolve on PATH. Confirm with command -v dockerd-rootless-setuptool.sh rootlesskit, which should print two /usr/bin paths.

  3. 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/subgid

    Expected:

    /etc/subuid:deploy:100000:65536
    /etc/subgid:deploy:100000:65536

    Ranges 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.

  4. 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.sock

    Expected: systemctl is-active docker prints inactive, and ls /var/run/docker.sock prints a “No such file or directory” error.

  5. Run the setup tool as the unprivileged user. Do not use sudo here. That is the whole point, and the script refuses to run as root anyway.

    dockerd-rootless-setuptool.sh install

    Expected: 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 own dockerd-rootless-setuptool.sh check subcommand runs the same pre-flight without installing anything.

  6. 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_HOST in 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 ls

    Expected: the rootless row carries an asterisk and the endpoint unix:///run/user/1000/docker.sock.

  7. 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=Linger

    Expected: Linger=yes. Then make the unit start on boot:

    systemctl --user enable --now docker
    systemctl --user is-enabled docker

    Expected: enabled.

  8. Delegate cgroup controllers so resource limits work. By default systemd only delegates a subset to user sessions, and --memory or --cpus will 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-reload

    Log out and back in, then confirm the controllers arrived:

    cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers

    Expected: cpuset cpu io memory pids.

  9. 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.

    Rootless networking path from an external client through RootlessKit and slirp4netns into the container namespace, with the unprivileged port boundary at 1024

    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_start

    Expected: 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 with systemctl --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.