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

  1. Install Debian on /dev/sda
  2. 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
    
  3. #apt update
    #apt install zfs-dkms docker.io
    
  4. 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
    
  5. Stop docker
      #systemctl stop docker.socket docker.service
    
  6. Remove docker storage folder - it will destroy all docker/images/volumes in the system
       #rm -rf /var/lib/docker
    
  7. Create docker dataset mounted to /var/lib/docker
       #zfs create -o mountpoint=/var/lib/docker storage/docker
    
  8. 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"
     }
    
  9. Check that docker is using ZFS for storage
    # docker info | grep Storage
    Storage Driver: zfs
    

    Done

Updated: