Assumtions
- System is Debian version 11.1 Bullseye
- Use bit older version of docker which comes from Debian, not one which is docker project provides itself.
- Host has 2 disks
- /dev/sda for OS itself
- /dev/sdb is dedicated for ZFS storage used by docker Nothing stops you to run Debian with Root-on-ZFS and build ZFS only system. It just pain to install at this moment. If you run Ubuntu than you are lucky, go for it.
Steps
- Install Debian on /dev/sda
- edit /etc/apt/sources.lst and add “contrib and non-free” to the list
deb http://deb.debian.org/debian/ bullseye main contrib non-free
-
#apt update #apt install zfs-dkms docker.io
- Create ZFS pool and set properties for root dataset
#/sbin/modprobe zfs #zpool create storage /dev/sdb #zpool status pool: storage state: ONLINE config: NAME STATE READ WRITE CKSUM storage ONLINE 0 0 0 sdb ONLINE 0 0 0 errors: No known data errors #zfs set compression=zstd-3 atime=off storage #zfs create -o mountpoint=/var/lib/docker storage/docker
- Stop docker
#systemctl stop docker.socket docker.service
- Remove docker storage folder - it will destroy all docker/images/volumes in the system
#rm -rf /var/lib/docker
- Create docker dataset mounted to /var/lib/docker
#zfs create -o mountpoint=/var/lib/docker storage/docker
- Configure Docker to use zfs. Edit /etc/docker/daemon.json and set the storage-driver to zfs. If the file was empty before, it should now look like this:
{ "storage-driver": "zfs" }
- Check that docker is using ZFS for storage
# docker info | grep Storage Storage Driver: zfs
Done