ehough / docker-nfs-server

A lightweight, robust, flexible, and containerized NFS server.
https://hub.docker.com/r/erichough/nfs-server/
GNU General Public License v3.0
672 stars 221 forks source link

Modprobe idea #18

Closed andyneff closed 5 years ago

andyneff commented 5 years ago

I found a trick you could optionally include in (maybe your more advanced?) documentation. There is a way to make a docker container run modprobe for you

Dockerfile (image with modprobe in it)

FROM fedora:29

SHELL ["/usr/bin/env", "bash", "-euxvc"]

RUN dnf install -y kmod; \
    rm -rf /var/cache/yum/*

docker-compose.yml

version: '2.3'
services:
  modprobe:
    image: modprobe
    build:
      context: .
    volumes:
      - type: bind
        source: /lib/modules
        target: /lib/modules
        read_only: true
    restart: "no"
    command: bash -euc 'modprobe nfsd; modprobe nfs'
    cap_add:
      - SYS_MODULE

Now you just make your nfs container server depend on that modprobe (maybe you'll have to add a wait routine instead of a check and fail on the lsmod check for nfs and nfsd?) and now you have a container that you can keep running through reboots.

You can of course combine these two into one container instead of two, but I don't know how universal this is (for example using a debian image on fedora, but I suspect that'll work)

Note for the modprobe, you only need SYS_MODULE capability

Base on https://dummdida.tumblr.com/post/117157045170/modprobe-in-a-docker-container


Thank for the awesome image!

ehough commented 5 years ago

That is an outrageously clever idea! Thanks for sharing it. At a minimum, I'm going to add this to the advanced docs, but I think it could be incorporated into entrypoint.sh (assuming the user gives the container SYS_MODULE).

Of course, I'll credit you for the idea. Thanks again!