Linux – Bind mount ZFS backed host directory in Docker container

dockerlinuxzfs

I have Docker 18.06.1-ce running on Ubuntu 18.04. Docker is running on a ext4 file system.

I have a raid array for big storage running ZFS. I would like to mount a directory from the ZFS array into a container. However, when attempting this, I get the following error:

docker run -it -v /mainpool/test:/mnt/mainpool busybox
docker: Error response from daemon: error while creating mount source path '/mainpool/test': mkdir /mainpool: read-only file system.

With some searching, I have seen some others have had the same issue. Like: https://www.reddit.com/r/docker/comments/93u3hf/unable_to_mount_zfs_host_directory_in_container

I do not want to move Docker to the ZFS file system for performance reasons. And it sounds like /var/lib/docker is a required to be in ZFS to use the ZFS storage driver.

Anyone have any thoughts on how to get around this?

EDIT: adding more info.

I am running Docker 18.06.1-ce in a snap. I am using the default daemon.json provided with the snap:

    "log-level":        "error",
    "storage-driver":   "aufs"

Some possible useful info from Docker:

Storage Driver: aufs
 Root Dir: /var/snap/docker/common/var-lib-docker/aufs
 Backing Filesystem: extfs
 Dirs: 192
 Dirperm1 Supported: true
Security Options:
 apparmor
 seccomp
  Profile: default
Docker Root Dir: /var/snap/docker/common/var-lib-docker

Possible relevant info from /proc/mounts:

/dev/nvme0n1p2 / ext4 rw,relatime,data=ordered 0 0
/dev/loop8 /snap/docker/321 squashfs ro,nodev,relatime 0 0
nsfs /run/snapd/ns/docker.mnt nsfs rw 0 0
mainpool /mainpool zfs rw,xattr,noacl 0 0 

Best Answer

@gertvdijk was correct.

After reinstalling docker from apt (outside snap) and making sure it was configured to use the overlay2 storage driver, I am able to bind mount directories on my zfs pool.

So, either running docker in a snap or using the aufs storage driver (instead of overlay2) was causing the issue with trying to mount directories from a zfs pool.