Sub topic 9
Where rootless Docker keeps its socket, data, and configuration
This chapter assumes you have a running rootless daemon and can connect the CLI to it. It covers where the daemon keeps its files, so you can back up data, edit settings, and debug connection problems.
Why the paths differ
A rootful daemon uses system locations such as /var/run/docker.sock, /var/lib/docker, and /etc/docker. An unprivileged user cannot write to those. Rootless Docker keeps everything under your home directory and your per-user runtime directory.
The locations follow the XDG base directory conventions. Three environment variables decide where things go:
XDG_RUNTIME_DIRis usually/run/user/<uid>. It is created by systemd at login and holds runtime files such as sockets.XDG_DATA_HOMEdefaults to~/.local/share.XDG_CONFIG_HOMEdefaults to~/.config.
The main locations
| Item | Default path |
|---|---|
| Client socket | `$XDG_RUNTIME_DIR/docker.sock` |
| Daemon data root | `$XDG_DATA_HOME/docker` (`~/.local/share/docker`) |
| Daemon configuration | `$XDG_CONFIG_HOME/docker/daemon.json` (`~/.config/docker/daemon.json`) |
| systemd user unit | `~/.config/systemd/user/docker.service` |
| Client configuration and contexts | `~/.docker/` |
| RootlessKit state | `$XDG_RUNTIME_DIR/dockerd-rootless` |
Two points are easy to miss. First, the daemon reads ~/.config/docker/daemon.json, not /etc/docker/daemon.json. Edits to the system file have no effect on the rootless daemon. Second, the socket lives in the runtime directory, which is removed when your last session ends unless lingering is enabled.
Inspecting the paths
You can confirm the real values instead of trusting the defaults.
echo "$XDG_RUNTIME_DIR"
ls -l "$XDG_RUNTIME_DIR/docker.sock"
docker info --format '{{.DockerRootDir}}'
systemctl --user cat docker | head -n 5DockerRootDir is the data root the running daemon actually uses. If you changed data-root in daemon.json, this command shows the new value.
Changing the configuration
Create or edit the user-level file, then restart the user service.
mkdir -p ~/.config/docker
cat > ~/.config/docker/daemon.json <<'EOF'
{
"log-level": "warn"
}
EOF
systemctl --user restart dockerRestarting the daemon stops running containers unless live-restore is configured, so plan changes for a quiet moment.
Working with the data directory
The data directory holds images, layers, volumes, and container metadata. Files inside it are owned by IDs from your subordinate range, not by your own user. In practice:
ls -lon files under~/.local/share/dockershows numeric owners such as100999, not your name.- A plain
rm -rffails on those files. Userootlesskit rm -rfinstead, as the uninstall step in a later chapter shows. - Backing up with a tool that runs as your user may skip or fail on those files. Run the backup through
rootlesskit, or export images and volumes with Docker commands.
Common mistakes
- Setting
DOCKER_HOSTto/var/run/docker.sock. That path points at the rootful daemon, if one exists. - Editing
/etc/docker/daemon.jsonand expecting the rootless daemon to change. - Running the daemon from a shell where
XDG_RUNTIME_DIRis unset, such as a plainsuorsudo -usession. The socket then ends up in the wrong place or the daemon fails to start.
Exercise
You added "data-root": "/mnt/big/docker" to /etc/docker/daemon.json, restarted the rootless daemon, and docker info still shows ~/.local/share/docker. What is wrong, and how do you fix it?
Show answer
The rootless daemon does not read /etc/docker/daemon.json. Put the setting in ~/.config/docker/daemon.json, make sure your user can write to /mnt/big/docker, and run systemctl --user restart docker. Then check docker info --format '{{.DockerRootDir}}'.