Sub topic 7
Managing the daemon with systemd --user
This chapter assumes you have already run dockerd-rootless-setuptool.sh install and know the basics of systemd units. Rootless Docker runs as a systemd user service, so you manage it with systemctl --user and never with sudo.
How the user service works
The setup tool installs a unit file named docker.service under ~/.config/systemd/user/. A user manager, systemd --user, runs as your account and starts the unit. The unit launches dockerd-rootless.sh, which starts the daemon inside a user namespace through RootlessKit.
Because the unit belongs to your user, it has your permissions. It can't bind low ports or change system-wide settings. It also doesn't appear in systemctl output without the --user flag.
Starting, stopping, and enabling
Use the same verbs you would use for a system service, but add --user:
systemctl --user start docker
systemctl --user enable docker
systemctl --user status docker
systemctl --user restart docker
systemctl --user stop dockerenable makes the daemon start when your user manager starts. Without lingering, that happens only when you log in.
Keeping the daemon running after logout
By default, systemd stops your user manager and all its services when your last session ends. The daemon and every container would stop with it. Lingering tells systemd to keep the user manager running.
sudo loginctl enable-linger "$(whoami)"
loginctl show-user "$(whoami)" --property=LingerThe second command should print Linger=yes. With lingering on and the unit enabled, the daemon starts at boot and survives logouts.
Reading logs
User services log to the journal. Query it with --user-unit:
journalctl --user -u docker.service --since "10 minutes ago"If journalctl --user shows nothing, your account may not have access to the persistent journal. Add your user to the systemd-journal group, or check that /var/log/journal exists.
Changing daemon settings
Edit ~/.config/docker/daemon.json for daemon options. Then restart the unit:
systemctl --user restart dockerTo change environment variables or the command line, don't edit the generated unit. Create a drop-in override:
systemctl --user edit docker.serviceAdd your changes in the editor, for example:
[Service]
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns"Save the file. systemd reloads the configuration, and you then restart the service for the change to take effect.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `Failed to connect to bus: No such file or directory` | `XDG_RUNTIME_DIR` is not set, often after `su` or `sudo -u` | Log in with a real session, or use `machinectl shell user@` |
| Daemon stops when you log out | Lingering is off | Run `sudo loginctl enable-linger` |
| `systemctl --user` says the unit isn't found | You ran the setup tool as another user, or with `sudo` | Re-run the setup tool as your own account |
| Unit fails right after boot | Network or runtime directory isn't ready yet | Check `journalctl --user -u docker.service` for the exact error |
Lifecycle at a glance
Exercise
You enabled the rootless docker unit and rebooted. The daemon isn't running until you log in over SSH, and it stops when you log out. What is missing, and how do you check it?
Show answer
Lingering is not enabled for your user. Run sudo loginctl enable-linger "$(whoami)", then confirm with loginctl show-user "$(whoami)" --property=Linger, which should print Linger=yes.
Exercise
Why should you use systemctl --user edit docker.service instead of editing the unit file the setup tool generated?
Show answer
The command creates a drop-in override that survives regeneration of the unit, for example when you re-run the setup tool. It keeps your changes separate from the generated file.