Sub topic 10
Storage drivers and filesystem considerations
This chapter assumes you have a working rootless daemon and know what an image layer is. It covers which storage drivers rootless Docker can use, how to choose one, and which filesystems cause problems.
Why the driver choice is different
A storage driver stacks image layers into one filesystem for each container. Rootful Docker usually uses overlay2, which relies on the kernel's overlay filesystem. Until recently, an unprivileged user could not mount an overlay filesystem. Rootless Docker therefore needs either a newer kernel or a fallback driver.
Available drivers
| Driver | Requirement | Trade-off |
|---|---|---|
| `overlay2` | Kernel 5.11 or later, or a distribution kernel with the rootless overlay patches | Best speed and disk use. Preferred when available. |
| `fuse-overlayfs` | Kernel 4.18 or later and the `fuse-overlayfs` package | Works on older kernels. Slower because it runs in user space. |
| `btrfs` | Data directory on btrfs, mounted with `user_subvol_rm_allowed` | Uses native copy-on-write. Needs a special mount option. |
| `vfs` | None | Works everywhere. Copies the full layer for every container, so it is slow and uses a lot of disk. |
Debian and Ubuntu kernels have allowed rootless overlay mounts for years, so overlay2 often works there even on older kernel versions.
Checking and setting the driver
The daemon picks a driver at startup. Ask the daemon which one it chose:
docker info --format '{{.Driver}}'To force a driver, create ~/.config/docker/daemon.json. This file replaces /etc/docker/daemon.json for the rootless daemon.
{
"storage-driver": "fuse-overlayfs"
}Restart the daemon so the change takes effect:
systemctl --user restart docker
docker info --format '{{.Driver}}'Filesystem considerations
The data directory is ~/.local/share/docker by default. Where it lives matters more than the driver in some cases.
- Network filesystems. Overlay-based drivers do not work on NFS. If your home directory is on NFS, set
data-rootindaemon.jsonto a local disk path that your user owns. - Ownership. Layer files are owned by subordinate UIDs and GIDs from
/etc/subuidand/etc/subgid. Ordinaryrmcannot delete them. Userootlesskit rm -rfwhen you remove the directory by hand. - Disk space. Each user has a separate data directory and image cache. Two users who pull the same image store it twice. Check
df -h ~/.local/share/dockerbefore pulling large images. - Bind mounts. Files you mount from the host keep your host UID. Inside the container they appear as root, because container root maps to your user. A container user other than root maps to a subordinate ID. That ID may not have permission to write to your files.
Common mistakes
- Setting
storage-driverin/etc/docker/daemon.json. The rootless daemon ignores that file. Edit~/.config/docker/daemon.json. - Installing the
fuse-overlayfspackage but not restarting the daemon. The driver is chosen at startup. - Changing drivers and expecting old images to appear. Each driver keeps its own data. After a change, you must pull or rebuild images.
Exercise
Your rootless daemon reports vfs as its storage driver, and you want better performance. Your kernel is 5.4 and not patched for rootless overlay. What do you do?
Show answer
Install the fuse-overlayfs package, which needs kernel 4.18 or later. Set "storage-driver": "fuse-overlayfs" in ~/.config/docker/daemon.json. Run systemctl --user restart docker, then confirm with docker info --format '{{.Driver}}'. Pull your images again, because each driver keeps its own data.