Skip to content

feat(module): docker-rootless - rootless Docker for a dedicated non-root account - #423

Merged
ycpss91255 merged 3 commits into
mainfrom
feat/docker-rootless-module
Nov 17, 2026
Merged

ycpss91255 merged 3 commits into
mainfrom
feat/docker-rootless-module

Conversation

@ycpss91255

@ycpss91255 ycpss91255 commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a docker-rootless module (archetype D, custom) that installs, upgrades and removes rootless Docker for one dedicated non-root account, GPU-ready. The existing docker module (rootful Engine) is untouched; the two coexist and are selected by socket:

  • rootful: /var/run/docker.sock
  • rootless: /run/user/<uid>/docker.sock (DOCKER_HOST=unix:///run/user/<uid>/docker.sock). Never use sudo docker to select rootless.

Parameters (environment variables):

  • DOCKER_ROOTLESS_USER - target account, default rootless.
  • DOCKER_ROOTLESS_DELEGATE - true (default) installs the user@<uid>.service drop-in Delegate=cpu cpuset io memory pids.

Lifecycle

install (idempotent; a second run is a no-op):

  1. Preflight: valid account name, not root, not in docker/sudo/admin, not the invoking account. Warn if the AppArmor unprivileged-userns restriction is active and no rootlesskit profile exists.
  2. Install uidmap and docker-ce-rootless-extras if missing, and record in a marker file (/var/lib/init_ubuntu/docker-rootless/<user>.pkgs) only the ones this module installed.
  3. Create the account if missing (no docker group, no sudo, locked password); ensure subuid/subgid.
  4. loginctl enable-linger; Delegate drop-in plus daemon-reload; start user@<uid>.service.
  5. Run dockerd-rootless-setuptool.sh install as the account (with XDG_RUNTIME_DIR / DBUS_SESSION_BUS_ADDRESS).
  6. Socket-wait ordering: After=user@UID.service alone is not enough because docker.sock appears later, so a user docker.service drop-in sets Restart=on-failure, RestartSec=3 and an ExecStartPost that waits (timeout 60) for %t/docker.sock. Units ordered After=docker.service therefore see the socket.
  7. systemctl --user enable --now docker.service.
  8. GPU: if nvidia-ctk is present and the runtime is not yet registered, run nvidia-ctk runtime configure --runtime=docker --config=<home>/.config/docker/daemon.json as the account (user-level only), then systemctl --user restart docker.service (the user daemon only). Idempotent: skipped when "nvidia" is already in that file. The module never touches /etc/docker, the rootful daemon, or /etc/nvidia-container-runtime/config.toml, and issues no restart of the rootful docker. Advisory warnings remain: warn if nvidia-cdi-refresh is missing, or if no-cgroups = true is set (keep the default, false).

upgrade: apt-get install --only-upgrade for both packages, re-apply the idempotent steps, try-restart the user docker service. Runs install if not installed.

remove (reverse sequence): stop user@UID.service and user-runtime-dir@UID.service, loginctl disable-linger, userdel -r, clean /etc/subuid and /etc/subgid, remove the Delegate drop-in, daemon-reload, then apt-get remove only the packages recorded in the marker. Refuses to delete an account that is in docker/sudo/admin or is the invoking account. Safe to run twice.

purge = remove plus dropping the module state dir. doctor checks account privileges, linger, subuid/subgid, user@UID, the socket and AppArmor. is_outdated uses apt list --upgradable. is_recommended is always false (opt-in).

Also: module INDEX regenerated, CHANGELOG entry under [Unreleased].

Testing

Run inside Docker via the repo's recipes:

  • just -f justfile.ci test-unit docker-rootless - 89 bats cases pass. Every system-changing command goes through a mocked sudo that also emulates the few file operations against a scratch root; nothing touches the host.
  • just -f justfile.ci lint (ShellCheck, fish, hadolint) - pass.
  • just -f justfile.ci test-unit (full unit suite, includes the module metadata and INDEX checks) - pass.
  • just -f justfile.ci test-integration - 24 ok, 0 not ok on the latest run (an earlier run had one environment-related harness failure, chown: invalid group: lifecycle:lifecycle, in a TUI spec unrelated to this change).

Real-host result

Run on one Ubuntu 26.04 host with one NVIDIA GPU and Docker 29.x, with live rootful workloads present:

  • install: rc=0; the account has only its own group (no docker, no sudo); linger enabled; user docker.service active; docker info shows rootless, cgroup v2 and the nvidia runtime; the account's daemon.json got the nvidia runtime; delegation shows cpuset cpu io memory pids.
  • Rootless docker run --gpus all and --device nvidia.com/gpu=all both show the GPU; the account cannot reach /var/run/docker.sock.
  • A second install is a no-op (no apt, no configure, no restart; the user dockerd PID is unchanged).
  • remove: rc=0; removes the account, subuid/subgid entries, the drop-in and uidmap. The rootful daemon (PID and start time), running containers, /etc/docker/daemon.json and /etc/nvidia-container-runtime/config.toml were byte-identical before and after.
  • That run found two leftovers, fixed in the last commit: libsubid5 (a dependency apt pulled in with uidmap) was not removed, and an empty /var/lib/init_ubuntu/docker-rootless remained. Install now records exactly the packages added by the apt run (installed-set diff, so new dependencies are included and pre-existing packages never are), and remove rmdirs the empty state dir and its parent only when empty. These two fixes are covered by bats only; they have not been re-run on the host.

NOT tested

  • Reboot recovery (linger, socket wait and Restart after a reboot).
  • upgrade.
  • Other Ubuntu versions (22.04 / 24.04 / 26.04 matrix) and hosts without a GPU.
  • The fixes for the two leftovers above on a real host.

Open points for review:

  • The socket wait is on the user docker.service (ExecStartPost), not a consumer unit; a consumer that cannot order after docker.service can still add its own ExecStartPre wait.

Closes #422

…oot account (#422)

Archetype D module that installs, upgrades and removes rootless Docker for
one dedicated account (DOCKER_ROOTLESS_USER, default 'rootless'): uidmap and
docker-ce-rootless-extras (only removed again if this module installed them),
subuid/subgid, linger, optional Delegate drop-in for user@UID.service,
dockerd-rootless-setuptool, and a user docker.service drop-in that waits for
docker.sock. Advisory AppArmor userns and NVIDIA CDI checks. remove reverses
the whole sequence and refuses to delete a privileged or invoking account.

Includes the bats spec (78 cases, all system commands mocked), regenerated
module INDEX and a CHANGELOG entry.
…account

When nvidia-ctk is present, run 'nvidia-ctk runtime configure --runtime=docker
--config=<home>/.config/docker/daemon.json' as the target account and restart
only the user docker.service, so --gpus all and --device nvidia.com/gpu=all
work rootless. Skipped when the runtime is already registered (idempotent).
User-level only: no rootful daemon, /etc/docker or nvidia-container-runtime
config.toml changes. The file lives in the account home, so remove (userdel -r)
discards it. Adds six bats cases (84 total).
… state dir

Record the packages added by the apt run (installed-set diff before/after),
so dependencies such as libsubid5 are removed on remove while packages that
were already installed never are. remove also rmdirs the empty module state
dir and its parent (only when empty). Five new bats cases (89 total).
@ycpss91255
ycpss91255 merged commit 2478650 into main Nov 17, 2026
12 checks passed
@ycpss91255
ycpss91255 deleted the feat/docker-rootless-module branch November 17, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(module): docker-rootless (rootless Docker for a low-privilege account, GPU-ready)

1 participant