modprobe in a docker container

… it is actually prossible.

You just need to make sure to:

  • Run the container in privileged mode (--privileged)
  • Add all capabilities (--cap-add=ALL)
  • Passthrough /lib/modules into the container (-v /lib/modules:/lib/modules)

You will end up with a commandline like:

$ docker run --name lvm --rm --privileged --cap-add=ALL -it -v /dev:/dev -v /lib/modules:/lib/modules docker.io/fabiand/centos7-lvm

Note: Loading a kernel module inside the container make it available on the host, and thus also on all other containers running on that host.