Docker loading kernel modules

user4725754 picture user4725754 · Oct 8, 2015 · Viewed 30.3k times · Source

I tried to install a kernel module, xfsprogs. It was successfully installed inside a container. It is really surprising, but lsmod doesn't list this module inside container or in the host system. How can a new kernel module loaded in a container?(CentOS container, Ubuntu host)

Answer

Tinkaal Gogoi picture Tinkaal Gogoi · May 11, 2016
  • Run the container in privileged mode (--privileged)
  • Add all capabilities (--cap-add=ALL)
  • mount host /lib/modules into the container (-v /lib/modules:/lib/modules)
docker run --name container_name --privileged --cap-add=ALL -d \
       -v /dev:/dev -v /lib/modules:/lib/modules image_id

Caution: Here all Linux capabilities are added so capabilities can be refined.