Install docker latest with ZFS as storage driver on Ubuntu 18.04.
Reminder before we go deep down in to the installation.
ZFS is only supported on Docker Engine - Community with Ubuntu 14.04 or higher, with the zfs package (16.04 and higher) or zfs-native and ubuntu-zfs packages (14.04) installed.
In this tutorial I'm using an aws ec2 instance with fresh installed Ubuntu 18.04 Let's get started
-
Setup the apt package and make sure you install packages to allow apt to use https repository
sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
-
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
Add the repository I'm using amd64 architecture
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
-
Install the docker engine
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io
-
Make sure you can run docker without sudo
sudo groupadd docker sudo usermod -aG docker $USER
After that make sure you logout from your session then login, and check the command docker
docker system info
Now you installed docker with overlay2 as storage driver and we gonna fix that
-
Stop the docker service for setup the zfs storage driver
sudo systemctl stop docker
-
Install the zfs package
sudo apt install zfsutils-linux
-
Make sure you use sudo su then delete the files on /var/lib/docker
sudo su sudo rm -rf /var/lib/docker/*
-
Make sure you have a drive for the pool
sudo fdisk -l
-
Create a new zpool and mount it on the /var/lib/docker
sudo zpool create -f zpool-docker -m /var/lib/docker /dev/xvdb1
-
Configure Docker to use
zfs
. Edit/etc/docker/daemon.json
and set thestorage-driver
tozfs
sudo vim /etc/docker/daemon.json { "storage-driver": "zfs" }
-
Start the docker service
sudo systemctl start docker
-
Now check the system info it should list zfs as storage driver
docker system info
-
Voila now you have a docker with zfs storage driver :D
Reference:
https://docs.docker.com/engine/install/ubuntu/
https://docs.docker.com/engine/install/linux-postinstall/
https://docs.docker.com/storage/storagedriver/zfs-driver/
https://ubuntu.com/tutorials/setup-zfs-storage-pool#3-creating-a-zfs-pool