Skip to content

MekayelAnik/nfs-server-alpine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NFS Server multi-arch image

A Multi-Aarch image for lightweight, highly customizable, containerized NFS server

NFS

This is an unofficial Multi-Aarch docker image of NFS Server created for multiplatform support. This image creates a local NFS Server to facilitate client-side data transfer. Official Website: https://wiki.linux-nfs.org

Docker Pulls

Docker Stars

The architectures supported by this image are:

Architecture Available Tag Status
x86-64 âś… amd64-<version tag> Tested "WORKING"
arm64 âś… arm64v8-<version tag> Tested "WORKING"
armhf âś… arm32v7-<version tag> Tested "WORKING"

Version Tags

Tag Available Description
latest âś… Stable "NFS releases
4.2 âś… Static "NFS" build version 4.2

Some Notes about NFS before you dive in:

- The first write after mounting the NFS-share takes sometime (Almost a minute). So if you immidiately try to write after mounting the share, it may seem it is hanged. But it is NOT. Give it some time.

- If you continue to use the NFS you may run into a **NFS stale** problem. To solve this please see THIS ARTICLE

- One container can only share One parent Directory and all its nested sub-directories. But you can't use one container to share multiple Parent directories or Drives. For this you have to containers for each Parent Directory or Disk.

Running Image :

Here are some example snippets to help you get started creating a container.

Docker Compose (recommended, click here for more info)

---
version: "3.9"
services:
  nfs-server:
    image: mekayelanik/nfs-server-alpine:latest
    container_name: nfs-server-1
    environment:
      - TZ=Asia/Dhaka
      - ALLOWED_CLIENT=192.168.1.1/24
      - NFS_MOUNT_PORT=2049
# Number of Shares without ROOT DIR
      - NUMBER_OF_SHARES=2
      - NFS_EXPORT_1=Movies
      - NFS_EXPORT_2=Music
    privileged: true
    volumes:
# # Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )
      - /lib/modules:/lib/modules
# NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
#### To create More than one NFS server container, please use MACVLAN as given example below.
      - /mnt/drive1:/data
      - /mnt/drive1/Movies:/data/Movies
      - /mnt/drive1/Music:/data/Music
    ports:
      - 2049:2049
      - 111:111
      - 32765-32767:32765-32767
# Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add).
    cap_add:
      - SYS_ADMIN
      - SETPCAP
      - ALL
    restart: unless-stopped
docker run -d \
  --name=nfs-server-alpine \
  -e TZ=Asia/Dhaka \
  -e NFS_MOUNT_PORT=2049 \
  -e NUMBER_OF_SHARES=2 \
  -e NFS_EXPORT_1=Movies\
  -e NFS_EXPORT_2=Music\
  -e TZ=Asia/Dhaka \
  -e ALLOWED_CLIENT=192.168.1.1/24 \
  -v /mnt/drive1:/data \
  -v /mnt/drive1/Movies:/data/Movies \
  -v /mnt/drive1/Music:/data/Music \
  --restart unless-stopped \
  mekayelanik/nfs-server-alpine:latest

If anyone wishes to give dedicated Local IP to NFS server container using MACVLAN ( click here for more info)

---
version: "3.9"
services:
  nfs-server:
    image: mekayelanik/nfs-server-alpine:latest
    container_name: nfs-server-1
    environment:
      - TZ=Asia/Dhaka
      - ALLOWED_CLIENT=192.168.1.1/24
      - NFS_MOUNT_PORT=2049
# Number of Shares without ROOT DIR
      - NUMBER_OF_SHARES=2
      - NFS_EXPORT_1=Movies
      - NFS_EXPORT_2=Music
    privileged: true
    volumes:
# # Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )
      - /lib/modules:/lib/modules
# NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
#### To create More than one NFS server container, please use MACVLAN as given example below.
      - /mnt/drive1:/data
      - /mnt/drive1/Movies:/data/Movies
      - /mnt/drive1/Music:/data/Music
    ports:
      - 2049:2049
      - 111:111
      - 32765-32767:32765-32767
# Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add).
    cap_add:
      - SYS_ADMIN
      - SETPCAP
      - ALL
    restart: unless-stopped
        hostname: nfs-server-1
    domainname: local
    mac_address: 14-24-34-44-54-64
    networks:
      macvlan-docker:
        ipv4_address: 192.168.1.21
#### Network Defination ####
networks:
  macvlan-docker:
    name: macvlan-docker
    external: True
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: "192.168.1.0/24"
          ip_range: "192.168.1.2/24"
          gateway: "192.168.1.1"

If anyone wishes to give dedicated Local IP to NFS server container using MACVLAN ( click here for more info)

---
version: "3.9"
services:
  nfs-server:
    image: mekayelanik/nfs-server-alpine:latest
    container_name: nfs-server
    environment:
      - TZ=Asia/Dhaka
      - ALLOWED_CLIENT=192.168.1.1/24
      - NFS_MOUNT_PORT=2049
# Number of Shares without ROOT DIR
      - NUMBER_OF_SHARES=2
      - NFS_EXPORT_1=Movies
      - NFS_EXPORT_2=Music
    privileged: true
    volumes:
# # Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )
      - /lib/modules:/lib/modules
# NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
#### To create More than one NFS server container, please use MACVLAN as given example below.
      - /mnt/drive1:/data
      - /mnt/drive1/Movies:/data/Movies
      - /mnt/drive1/Music:/data/Music
    ports:
      - 2049:2049
      - 111:111
      - 32765-32767:32765-32767
# Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add).
    cap_add:
      - SYS_ADMIN
      - SETPCAP
      - ALL
    restart: unless-stopped
        hostname: nfs-server
    domainname: local
    mac_address: 14-24-34-44-54-64
    networks:
      macvlan-docker:
        ipv4_address: 192.168.1.21
#### Network Defination ####
networks:
  macvlan-docker:
    name: macvlan-docker
    external: True
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: "192.168.1.0/24"
          ip_range: "192.168.1.2/24"
          gateway: "192.168.1.1"

If anyone wishes to give dedicated Local IP to NFS server container using MACVLAN ( click here for more info)

Creating A MACVLAN First. Example is Below


docker network create -d macvlan \ 
    --subnet=192.168.0.0/16 \       ####    Set your Subnet here and remove this comment    ####
    --ip-range=192.168.1.0/16 \     ####    Set your Desired IP range fr this MACVLAN here. (You can set IP to your CONTAINERs from this range) and remove this comment    ####
    --gateway=192.168.0.1 \         ####    Set your Original Network Gateway or Router's Local IP here and remove this comment    ####
    -o parent=eth0 macvlan-docker   ####    Set your network interface in the "parent=" (In Raspberrypi parent is 'eth0' in mordern x86 systems it is 'enp4s0'. Find yours by running "tcpdump --list-interfaces" ) & desired MACVLAN Nework name in the end (Here I have set the name to macvlan-docker) IP here and remove this comment    ####

Creating Container n MACVLAN. Example is Below

---
version: "3.9"
services:
  nfs-server:
    image: mekayelanik/nfs-server-alpine:latest
    container_name: nfs-server-1
    environment:
      - TZ=Asia/Dhaka
      - ALLOWED_CLIENT=192.168.1.1/24
      - NFS_MOUNT_PORT=2049
# Number of Shares without ROOT DIR
      - NUMBER_OF_SHARES=2
      - NFS_EXPORT_1=Movies
      - NFS_EXPORT_2=Music
    privileged: true
    volumes:
# # Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )
      - /lib/modules:/lib/modules
# NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
#### To create More than one NFS server container, please use MACVLAN as given example below.
      - /mnt/drive1:/data
      - /mnt/drive1/Movies:/data/Movies
      - /mnt/drive1/Music:/data/Music
    ports:
      - 2049:2049
      - 111:111
      - 32765-32767:32765-32767
# Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add).
    cap_add:
      - SYS_ADMIN
      - SETPCAP
      - ALL
    restart: unless-stopped
        hostname: nfs-server-1
    domainname: local
    mac_address: 14-24-34-44-54-64
    networks:
      macvlan-docker:
        ipv4_address: 192.168.1.21
        #### Network Defination ####  
        networks:
          macvlan-docker:
            name: macvlan-docker
            external: True

If anyone wishes to SHARE FROM MORE THAN ONE PARENT DIRECTORY please use this MACVLAN approch

---
    version: "3.9"
    services:
########### Conatiner for Share from Parent Direnctory-1 or Disk-1 ###########
        nfs-server-disk1:
            image: mekayelanik/nfs-server-alpine:latest
            container_name: nfs-server-disk1
            environment:
                - TZ=Asia/Dhaka
                - ALLOWED_CLIENT=192.168.1.1/24
                - NFS_MOUNT_PORT=2049
        # Number of Shares without ROOT DIR
                - NUMBER_OF_SHARES=2
                - NFS_EXPORT_1=Movies
                - NFS_EXPORT_2=Music
            privileged: true
            volumes:
            ### Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )  ###
                - /lib/modules:/lib/modules
        # NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
        ## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
        ### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
        #### To create More than one NFS server container, please use MACVLAN as given example below.
                - /mnt/drive1:/data
                - /mnt/drive1/Movies:/data/Movies
                - /mnt/drive1/Music:/data/Music
            ports:
                - 2049:2049
                - 111:111
                - 32765-32767:32765-32767
        ### Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add). ###
            cap_add:
                - SYS_ADMIN
                - SETPCAP
                - ALL
            restart: unless-stopped
            hostname: nfs-server-1
            domainname: local
            mac_address: ab-cd-ef-ab-cd-a1
            networks:
                macvlan-docker:
                    ipv4_address: 192.168.249.101
########### Conatiner for Share from Parent Direnctory-2 or Disk-2 ###########
        nfs-server-disk2:
            image: mekayelanik/nfs-server-alpine:latest
            container_name: nfs-server-disk2
            environment:
                - TZ=Asia/Dhaka
                - ALLOWED_CLIENT=192.168.1.1/24
                - NFS_MOUNT_PORT=2049
            # Number of Shares without ROOT DIR
                - NUMBER_OF_SHARES=2
                - NFS_EXPORT_1=Games
                - NFS_EXPORT_2=Softwares
            privileged: true
            volumes:
            # # Don't touch the FOLLOWING Mapping (/lib/modules). This is REQUIRED to run NFS as a container. ('sys_module' modprobe )
                - /lib/modules:/lib/modules
            # NFS Root directory in this container '/data' MUST BE MAPPED to a valid directory in the Host (Server Machine)
            ## You CAN'T use different parent directory (for example /mnt/drive2/Movies) for child shares.
            ### To share different Child shares on another Parent directory, you must use deploy another container. (Sorry, but this is how the NFS works)
            #### To create More than one NFS server container, please use MACVLAN as given example below.
                - /mnt/drive2:/data
                - /mnt/drive2/Games:/data/Games
                - /mnt/drive2/Softwares:/data/Softwares
            ports:
                - 2049:2049
                - 111:111
                - 32765-32767:32765-32767
            # Don't touch the FOLLOWING Section. This is REQUIRED to run NFS as a container (cap_add).
            cap_add:
                - SYS_ADMIN
                - SETPCAP
                - ALL
            restart: unless-stopped
            hostname: nfs-server-disk2
            domainname: local
            mac_address: ab-cd-ef-ab-cd-a2
            networks:
                macvlan-docker:
                    ipv4_address: 192.168.249.102
    #### Network Defination ####  
    networks:
      macvlan-docker:
        name: macvlan-docker
        external: True

In order to mount NFS share run the Following on Client Machine

# To mount ROOT_DIR
sudo mount -v -o vers=4.2,loud HOST-IP:/ /mount/path/to/ROOT-MOUNT-DIR
Example: sudo mount -v -o vers=4.2,loud 192.168.1.2:/ /mount/path/to/ROOT-MOUNT-DIR
# To mount Child Shares (via Command Line)
sudo mount -v -o vers=4.2,loud HOST-IP:/Movies /nfs_shares/Movies
sudo mount -v -o vers=4.2,loud HOST-IP:/Music /nfs_shares/Music
Example:  
mkdir -p /nfs_shares/Movies && \
sudo mount -v -o vers=4.2,loud 192.168.1.2:/Movies  /nfs_shares/Movies

To Mount Using FSTAB, Add the following in the '/etc/fstab'

 ##### NFS-Share Mounts #####
    192.168.249.101:/ /nfs_shares nfs nofail,noauto,x-systemd.automount
    192.168.249.101:/Movies /nfs_shares/Movies nfs nofail,noauto,x-systemd.automount
    192.168.249.101:/Music /nfs_shares/Music nfs nofail,noauto,x-systemd.automount

To Un-mount

sudo umount  /nfs_shares/Movies

Updating Info

Below are the instructions for updating containers:

Via Docker Compose (recommended)

  • Update all images: docker compose pull
    • or update a single image: docker compose pull mekayelanik/nfs-server-alpine
  • Let compose update all containers as necessary: docker compose up -d
    • or update a single container (recommended): docker compose up -d nfs-server-alpine
  • To remove the old unused images run: docker image prune

Via Docker Run

  • Update the image: docker pull mekayelanik/nfs-server-alpine:latest
  • Stop the running container: docker stop nfs-server-alpine
  • Delete the container: docker rm nfs-server-alpine
  • To remove the old unused images run: docker image prune

Via Watchtower auto-updater (only use if you don't remember the original parameters)

  • Pull the latest image at its tag and replace it with the same env variables in one run:

    docker run --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower\
    --run-once nfs-server-alpine
  • To remove the old unused images run: docker image prune

Note: You can use Watchtower as a solution to automated updates of existing Docker containers. But it is discouraged to use automated updates. However, this is a useful tool for one-time manual updates of containers where you have forgotten the original parameters. In the long term, it is recommend to use Docker Compose.

Image Update Notifications - Diun (Docker Image Update Notifier)

  • You can also use Diun for update notifications. Other tools that automatically update containers unattended are not encouraged

Issues & Requests

To submit this Docker image specific issues or requests visit this docker image's Github Link: https://github.com/MekayelAnik/nfs-server-alpine

For NFS related issues please visit: http://www.linux-nfs.org/wiki/index.php/Main_Page

About

A Multi-Aarch Docker image for lightweight, highly customizable, containerized NFS server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published