How to install ZFS inside Rockylinux Docker container?

I have created a Dockerfile:

FROM rockylinux:8.6

RUN yum -y update && yum -y install git && yum clean all

RUN    yum -y install 'dnf-command(config-manager)' \
    && yum -y install https://zfsonlinux.org/epel/zfs-release.el8_6.noarch.rpm \
    && rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux \
    && yum config-manager --disable zfs \
    && yum config-manager --enable zfs-kmod \
    && yum -y install zfs \
    && yum clean all \
    && echo zfs >/etc/modules-load.d/zfs.conf

I am building it:

docker build --platform linux/amd64 -t glacier_deep_archive_backup-amd64 .

However, the ZFS module is not loaded:

>docker run --platform linux/amd64 --rm -it glacier_deep_archive_backup-amd64 bash
[root@4840df736355 /]# modprobe zfs
modprobe: FATAL: Module zfs not found in directory /lib/modules/5.10.124-linuxkit

The /lib/modules/5.10.124-linuxkit directory is not existing inside the container.

How to load the ZFS module?

You enabled a repo called ‘zfs-kmod’, then installed something called ‘zfs’, but are you sure ‘zfs’ exists in ‘kmod’?
If so, whereever you ran

yum -y install zfs

run this

rpm -ql zfs

Yes, I am sure. It is working on non-dockered-containers.

Within the container:

[root@62eb2739b66d /]# rpm -ql zfs
/etc/sudoers.d/zfs
/etc/zfs/vdev_id.conf.alias.example
/etc/zfs/vdev_id.conf.multipath.example
/etc/zfs/vdev_id.conf.sas_direct.example
/etc/zfs/vdev_id.conf.sas_switch.example
/etc/zfs/vdev_id.conf.scsi.example
/etc/zfs/zed.d/all-syslog.sh
/etc/zfs/zed.d/data-notify.sh
/etc/zfs/zed.d/history_event-zfs-list-cacher.sh
/etc/zfs/zed.d/pool_import-led.sh
/etc/zfs/zed.d/resilver_finish-notify.sh
/etc/zfs/zed.d/resilver_finish-start-scrub.sh
/etc/zfs/zed.d/scrub_finish-notify.sh
/etc/zfs/zed.d/statechange-led.sh
/etc/zfs/zed.d/statechange-notify.sh
/etc/zfs/zed.d/vdev_attach-led.sh
/etc/zfs/zed.d/vdev_clear-led.sh
/etc/zfs/zed.d/zed-functions.sh
/etc/zfs/zed.d/zed.rc
/etc/zfs/zpool.d/ata_err
/etc/zfs/zpool.d/cmd_to
/etc/zfs/zpool.d/defect
/etc/zfs/zpool.d/dm-deps
/etc/zfs/zpool.d/enc
/etc/zfs/zpool.d/encdev
/etc/zfs/zpool.d/fault_led
/etc/zfs/zpool.d/health
/etc/zfs/zpool.d/hours_on
/etc/zfs/zpool.d/iostat
/etc/zfs/zpool.d/iostat-10s
/etc/zfs/zpool.d/iostat-1s
/etc/zfs/zpool.d/label
/etc/zfs/zpool.d/locate_led
/etc/zfs/zpool.d/lsblk
/etc/zfs/zpool.d/media
/etc/zfs/zpool.d/model
/etc/zfs/zpool.d/nonmed
/etc/zfs/zpool.d/nvme_err
/etc/zfs/zpool.d/off_ucor
/etc/zfs/zpool.d/pend_sec
/etc/zfs/zpool.d/pwr_cyc
/etc/zfs/zpool.d/r_proc
/etc/zfs/zpool.d/r_ucor
/etc/zfs/zpool.d/realloc
/etc/zfs/zpool.d/rep_ucor
/etc/zfs/zpool.d/serial
/etc/zfs/zpool.d/ses
/etc/zfs/zpool.d/size
/etc/zfs/zpool.d/slot
/etc/zfs/zpool.d/smart
/etc/zfs/zpool.d/smart_test
/etc/zfs/zpool.d/smartx
/etc/zfs/zpool.d/temp
/etc/zfs/zpool.d/test_ended
/etc/zfs/zpool.d/test_progress
/etc/zfs/zpool.d/test_status
/etc/zfs/zpool.d/test_type
/etc/zfs/zpool.d/upath
/etc/zfs/zpool.d/vendor
/etc/zfs/zpool.d/w_proc
/etc/zfs/zpool.d/w_ucor
/sbin/fsck.zfs
/sbin/mount.zfs
/sbin/zdb
/sbin/zed
/sbin/zfs
/sbin/zfs_ids_to_path
/sbin/zgenhostid
/sbin/zhack
/sbin/zinject
/sbin/zpool
/sbin/zstream
/sbin/zstreamdump
/sbin/ztest
/usr/bin/arc_summary
/usr/bin/arcstat
/usr/bin/dbufstat
/usr/bin/raidz_test
/usr/bin/zvol_wait
/usr/lib/.build-id
/usr/lib/.build-id/04
/usr/lib/.build-id/04/2a1496bccaeef992af214959604813a7a447be
/usr/lib/.build-id/06
/usr/lib/.build-id/06/5360974481588c8ea4695abcff688a9b67fc3e
/usr/lib/.build-id/0a
/usr/lib/.build-id/0a/0dad7231fc44e769f3aeaec814f9a9df308869
/usr/lib/.build-id/2c
/usr/lib/.build-id/2c/32c3332a7829db84a5825cb037fa05cb2fe236
/usr/lib/.build-id/43
/usr/lib/.build-id/43/c756ceb9eda4a3b50b6e4d5edefedbd34fae54
/usr/lib/.build-id/5e
/usr/lib/.build-id/5e/2df11aa9ec5f7fc560cc21c6e150a2dcb5d2a6
/usr/lib/.build-id/76
/usr/lib/.build-id/76/246f0595ae002c3d956568bebeaa43694d9320
/usr/lib/.build-id/97
/usr/lib/.build-id/97/6ff43b7d997155394c93319cccba91232f0c7f
/usr/lib/.build-id/99
/usr/lib/.build-id/99/c927523885f7369c227101f9ab0ac43a64e2e1
/usr/lib/.build-id/a4
/usr/lib/.build-id/a4/66a0a9dc3dc03e0be9fd427bf3ecce3860fa91
/usr/lib/.build-id/aa
/usr/lib/.build-id/aa/e62ca708d15877095409a594b5e10bb0c5efa9
/usr/lib/.build-id/bf
/usr/lib/.build-id/bf/ea3dd456c28f0afabad49844ca5c32a8d6b82e
/usr/lib/.build-id/e1
/usr/lib/.build-id/e1/51c784b2e73bf0baebcb07c4d483a755594d7e
/usr/lib/.build-id/f7
/usr/lib/.build-id/f7/c1c76ce74446787c0944d309258b1850131e3b
/usr/lib/.build-id/fa
/usr/lib/.build-id/fa/839cc40c898c013bb629a16eff39541649f9d7
/usr/lib/modules-load.d/zfs.conf
/usr/lib/systemd/system-generators/zfs-mount-generator
/usr/lib/systemd/system-preset/50-zfs.preset
/usr/lib/systemd/system/zfs-import-cache.service
/usr/lib/systemd/system/zfs-import-scan.service
/usr/lib/systemd/system/zfs-import.service
/usr/lib/systemd/system/zfs-import.target
/usr/lib/systemd/system/zfs-mount.service
/usr/lib/systemd/system/zfs-scrub-monthly@.timer
/usr/lib/systemd/system/zfs-scrub-weekly@.timer
/usr/lib/systemd/system/zfs-scrub@.service
/usr/lib/systemd/system/zfs-share.service
/usr/lib/systemd/system/zfs-volume-wait.service
/usr/lib/systemd/system/zfs-volumes.target
/usr/lib/systemd/system/zfs-zed.service
/usr/lib/systemd/system/zfs.target
/usr/lib/udev/rules.d/60-zvol.rules
/usr/lib/udev/rules.d/69-vdev.rules
/usr/lib/udev/rules.d/90-zfs.rules
/usr/lib/udev/vdev_id
/usr/lib/udev/zvol_id
/usr/libexec/zfs
/usr/libexec/zfs/zed.d
/usr/libexec/zfs/zed.d/all-debug.sh
/usr/libexec/zfs/zed.d/all-syslog.sh
/usr/libexec/zfs/zed.d/data-notify.sh
/usr/libexec/zfs/zed.d/generic-notify.sh
/usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh
/usr/libexec/zfs/zed.d/pool_import-led.sh
/usr/libexec/zfs/zed.d/resilver_finish-notify.sh
/usr/libexec/zfs/zed.d/resilver_finish-start-scrub.sh
/usr/libexec/zfs/zed.d/scrub_finish-notify.sh
/usr/libexec/zfs/zed.d/statechange-led.sh
/usr/libexec/zfs/zed.d/statechange-notify.sh
/usr/libexec/zfs/zed.d/trim_finish-notify.sh
/usr/libexec/zfs/zed.d/vdev_attach-led.sh
/usr/libexec/zfs/zed.d/vdev_clear-led.sh
/usr/libexec/zfs/zpool.d
/usr/libexec/zfs/zpool.d/ata_err
/usr/libexec/zfs/zpool.d/cmd_to
/usr/libexec/zfs/zpool.d/defect
/usr/libexec/zfs/zpool.d/dm-deps
/usr/libexec/zfs/zpool.d/enc
/usr/libexec/zfs/zpool.d/encdev
/usr/libexec/zfs/zpool.d/fault_led
/usr/libexec/zfs/zpool.d/health
/usr/libexec/zfs/zpool.d/hours_on
/usr/libexec/zfs/zpool.d/iostat
/usr/libexec/zfs/zpool.d/iostat-10s
/usr/libexec/zfs/zpool.d/iostat-1s
/usr/libexec/zfs/zpool.d/label
/usr/libexec/zfs/zpool.d/locate_led
/usr/libexec/zfs/zpool.d/lsblk
/usr/libexec/zfs/zpool.d/media
/usr/libexec/zfs/zpool.d/model
/usr/libexec/zfs/zpool.d/nonmed
/usr/libexec/zfs/zpool.d/nvme_err
/usr/libexec/zfs/zpool.d/off_ucor
/usr/libexec/zfs/zpool.d/pend_sec
/usr/libexec/zfs/zpool.d/pwr_cyc
/usr/libexec/zfs/zpool.d/r_proc
/usr/libexec/zfs/zpool.d/r_ucor
/usr/libexec/zfs/zpool.d/realloc
/usr/libexec/zfs/zpool.d/rep_ucor
/usr/libexec/zfs/zpool.d/serial
/usr/libexec/zfs/zpool.d/ses
/usr/libexec/zfs/zpool.d/size
/usr/libexec/zfs/zpool.d/slot
/usr/libexec/zfs/zpool.d/smart
/usr/libexec/zfs/zpool.d/smart_test
/usr/libexec/zfs/zpool.d/smartx
/usr/libexec/zfs/zpool.d/temp
/usr/libexec/zfs/zpool.d/test_ended
/usr/libexec/zfs/zpool.d/test_progress
/usr/libexec/zfs/zpool.d/test_status
/usr/libexec/zfs/zpool.d/test_type
/usr/libexec/zfs/zpool.d/upath
/usr/libexec/zfs/zpool.d/vendor
/usr/libexec/zfs/zpool.d/w_proc
/usr/libexec/zfs/zpool.d/w_ucor
/usr/libexec/zfs/zpool_influxdb
/usr/share/man/man1/arcstat.1.gz
/usr/share/man/man1/raidz_test.1.gz
/usr/share/man/man1/test-runner.1.gz
/usr/share/man/man1/zhack.1.gz
/usr/share/man/man1/ztest.1.gz
/usr/share/man/man1/zvol_wait.1.gz
/usr/share/man/man4/spl.4.gz
/usr/share/man/man4/zfs.4.gz
/usr/share/man/man5/vdev_id.conf.5.gz
/usr/share/man/man7/dracut.zfs.7.gz
/usr/share/man/man7/zfsconcepts.7.gz
/usr/share/man/man7/zfsprops.7.gz
/usr/share/man/man7/zpool-features.7.gz
/usr/share/man/man7/zpoolconcepts.7.gz
/usr/share/man/man7/zpoolprops.7.gz
/usr/share/man/man8/fsck.zfs.8.gz
/usr/share/man/man8/mount.zfs.8.gz
/usr/share/man/man8/vdev_id.8.gz
/usr/share/man/man8/zdb.8.gz
/usr/share/man/man8/zed.8.gz
/usr/share/man/man8/zfs-allow.8.gz
/usr/share/man/man8/zfs-bookmark.8.gz
/usr/share/man/man8/zfs-change-key.8.gz
/usr/share/man/man8/zfs-clone.8.gz
/usr/share/man/man8/zfs-create.8.gz
/usr/share/man/man8/zfs-destroy.8.gz
/usr/share/man/man8/zfs-diff.8.gz
/usr/share/man/man8/zfs-get.8.gz
/usr/share/man/man8/zfs-groupspace.8.gz
/usr/share/man/man8/zfs-hold.8.gz
/usr/share/man/man8/zfs-inherit.8.gz
/usr/share/man/man8/zfs-jail.8.gz
/usr/share/man/man8/zfs-list.8.gz
/usr/share/man/man8/zfs-load-key.8.gz
/usr/share/man/man8/zfs-mount-generator.8.gz
/usr/share/man/man8/zfs-mount.8.gz
/usr/share/man/man8/zfs-program.8.gz
/usr/share/man/man8/zfs-project.8.gz
/usr/share/man/man8/zfs-projectspace.8.gz
/usr/share/man/man8/zfs-promote.8.gz
/usr/share/man/man8/zfs-receive.8.gz
/usr/share/man/man8/zfs-recv.8.gz
/usr/share/man/man8/zfs-redact.8.gz
/usr/share/man/man8/zfs-release.8.gz
/usr/share/man/man8/zfs-rename.8.gz
/usr/share/man/man8/zfs-rollback.8.gz
/usr/share/man/man8/zfs-send.8.gz
/usr/share/man/man8/zfs-set.8.gz
/usr/share/man/man8/zfs-share.8.gz
/usr/share/man/man8/zfs-snapshot.8.gz
/usr/share/man/man8/zfs-unallow.8.gz
/usr/share/man/man8/zfs-unjail.8.gz
/usr/share/man/man8/zfs-unload-key.8.gz
/usr/share/man/man8/zfs-unmount.8.gz
/usr/share/man/man8/zfs-upgrade.8.gz
/usr/share/man/man8/zfs-userspace.8.gz
/usr/share/man/man8/zfs-wait.8.gz
/usr/share/man/man8/zfs.8.gz
/usr/share/man/man8/zfs_ids_to_path.8.gz
/usr/share/man/man8/zgenhostid.8.gz
/usr/share/man/man8/zinject.8.gz
/usr/share/man/man8/zpool-add.8.gz
/usr/share/man/man8/zpool-attach.8.gz
/usr/share/man/man8/zpool-checkpoint.8.gz
/usr/share/man/man8/zpool-clear.8.gz
/usr/share/man/man8/zpool-create.8.gz
/usr/share/man/man8/zpool-destroy.8.gz
/usr/share/man/man8/zpool-detach.8.gz
/usr/share/man/man8/zpool-events.8.gz
/usr/share/man/man8/zpool-export.8.gz
/usr/share/man/man8/zpool-get.8.gz
/usr/share/man/man8/zpool-history.8.gz
/usr/share/man/man8/zpool-import.8.gz
/usr/share/man/man8/zpool-initialize.8.gz
/usr/share/man/man8/zpool-iostat.8.gz
/usr/share/man/man8/zpool-labelclear.8.gz
/usr/share/man/man8/zpool-list.8.gz
/usr/share/man/man8/zpool-offline.8.gz
/usr/share/man/man8/zpool-online.8.gz
/usr/share/man/man8/zpool-reguid.8.gz
/usr/share/man/man8/zpool-remove.8.gz
/usr/share/man/man8/zpool-reopen.8.gz
/usr/share/man/man8/zpool-replace.8.gz
/usr/share/man/man8/zpool-resilver.8.gz
/usr/share/man/man8/zpool-scrub.8.gz
/usr/share/man/man8/zpool-set.8.gz
/usr/share/man/man8/zpool-split.8.gz
/usr/share/man/man8/zpool-status.8.gz
/usr/share/man/man8/zpool-sync.8.gz
/usr/share/man/man8/zpool-trim.8.gz
/usr/share/man/man8/zpool-upgrade.8.gz
/usr/share/man/man8/zpool-wait.8.gz
/usr/share/man/man8/zpool.8.gz
/usr/share/man/man8/zpool_influxdb.8.gz
/usr/share/man/man8/zstream.8.gz
/usr/share/man/man8/zstreamdump.8.gz
/usr/share/zfs/compatibility.d
/usr/share/zfs/compatibility.d/2018
/usr/share/zfs/compatibility.d/2019
/usr/share/zfs/compatibility.d/2020
/usr/share/zfs/compatibility.d/2021
/usr/share/zfs/compatibility.d/compat-2018
/usr/share/zfs/compatibility.d/compat-2019
/usr/share/zfs/compatibility.d/compat-2020
/usr/share/zfs/compatibility.d/compat-2021
/usr/share/zfs/compatibility.d/freebsd-11.0
/usr/share/zfs/compatibility.d/freebsd-11.1
/usr/share/zfs/compatibility.d/freebsd-11.2
/usr/share/zfs/compatibility.d/freebsd-11.3
/usr/share/zfs/compatibility.d/freebsd-11.4
/usr/share/zfs/compatibility.d/freebsd-12.0
/usr/share/zfs/compatibility.d/freebsd-12.1
/usr/share/zfs/compatibility.d/freebsd-12.2
/usr/share/zfs/compatibility.d/freenas-11.0
/usr/share/zfs/compatibility.d/freenas-11.1
/usr/share/zfs/compatibility.d/freenas-11.2
/usr/share/zfs/compatibility.d/freenas-11.3
/usr/share/zfs/compatibility.d/freenas-9.10.2
/usr/share/zfs/compatibility.d/grub2
/usr/share/zfs/compatibility.d/openzfs-2.0-freebsd
/usr/share/zfs/compatibility.d/openzfs-2.0-linux
/usr/share/zfs/compatibility.d/openzfs-2.1-freebsd
/usr/share/zfs/compatibility.d/openzfs-2.1-linux
/usr/share/zfs/compatibility.d/openzfsonosx-1.7.0
/usr/share/zfs/compatibility.d/openzfsonosx-1.8.1
/usr/share/zfs/compatibility.d/openzfsonosx-1.9.3
/usr/share/zfs/compatibility.d/openzfsonosx-1.9.4
/usr/share/zfs/compatibility.d/truenas-12.0
/usr/share/zfs/compatibility.d/ubuntu-18.04
/usr/share/zfs/compatibility.d/ubuntu-20.04
/usr/share/zfs/compatibility.d/zol-0.6.1
/usr/share/zfs/compatibility.d/zol-0.6.4
/usr/share/zfs/compatibility.d/zol-0.6.5
/usr/share/zfs/compatibility.d/zol-0.7
/usr/share/zfs/compatibility.d/zol-0.8

That would suggest that a kernel and/or kernel-modules package are not installed. Also a search using dnf doesn’t show a linuxkit kernel. As far as I am aware, docker containers do not contain a kernel, which means it’s not going to work. So unless you can get the kernel/kernel-modules installed for that particular kernel in your container, you won’t be able to load the module.

See this reddit post: https://www.reddit.com/r/zfs/comments/gn2ubp/using_zfs_inside_docker_container/ which may help you getting it to work in docker, alternatively, run a VM instead.

And also from a google for do docker containers have their own kernel

Thank you.

My wish was not to use a VM but to get a docker container as part of a pipeline to perform automated tests whose a piece of steps relies on handling a ZFS pool.

Apart from all of the above, I can’t see a zfs module in the long list of files in the package, so I don’t know how the module would even work outside of docker?

It is the way that ZFS is working if you are not familiar with ZFS on Linux (refer to RHEL-based distro — OpenZFS documentation)

I now see (in the initial post) the package zfs-release.el8_6.noarch.rpm, using url style, in addition to the ‘zfs’ package.