Stories, essays, learning, and other considerations
By Jehan

Ext4 Filesystem in ZFS a pool (for Docker)

Those who’ve tried using docker’s zfs storage driver on linux will know that it’s not as well-supported as others. It’s decent, it works, but you can hit some limitations such as zfs filesystems that aren’t removed correctly, or don’t exist so they can’t be removed or k3s not working without support for overlayfs.

In my experience, it has also been quite slow and ressource-intensive.

Support for OverlayFS2 on ZFS is coming soon, but it’s not there yet. While looking for a work-around, I found out an elegant solution: use a zvol.

In short, it is possible to create any kind of filesystem (in our case: ext4) within a ZFS pool, by exposing a ZVOL:

So I created a zvol with an ext4 filesystem in it:

1
2
zfs create -s -V 90GB zpool/docker
mkfs.ext4 /dev/zvol/zpool/docker

Then I stopped the docker daemon and cleaned /var/lib/docker:

1
sudo systemctl stop docker

As root:

1
cd /var/lib/docker/ && rm -rI *

Then I mounted the filesystem. In /etc/fstab:

1
/dev/zvol/zpool/docker /var/lib/docker ext4 defaults,_netdev 0 0

Then:

1
sudo mount /var/lib/docker

Also, in my docker config (in /etc/docker/daemon.json), I changed the storage driver:

1
2
3
// ...
    "storage-driver": "overlay2",
// ...

Finally, I restarted restart docker.