In this post we will see how quick and fast it is to setup a NFS Server using a Docker container using itsthenetwork/nfs-server-alpine.

If you would like to install NFS Server using a non-docker based deployment, you can have a look at installing nfs server on ubuntu


On our host we will use the local path: /data/docker-volumes to mount inside the container to /data and expose the port 2049 from the container to the host.

Getting Started

I'm assuming that you have docker and docker-compose installed.

Create the local directory:

$ mkdir -p /data/docker-volumes

Next, create the docker-compose.yml

version: "2.1"
    image: itsthenetwork/nfs-server-alpine:12
    container_name: nfs
    restart: unless-stopped
    privileged: true
      - SHARED_DIRECTORY=/data
      - /data/docker-volumes:/data
      - 2049:2049

Boot the container:

$ docker-compose up -d

To test our NFS Server, let's install the NFS client to our host:

$ sudo apt install nfs-client -y

Now let's mount our NFS mount to our local path: /mnt:

$ sudo mount -v -o vers=4,loud /mnt

Verify that the mount is showing:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       109G   53G   51G  52% /   4.5T  2.2T  2.1T  51% /mnt

Now, create a test file on our NFS export:

$ touch /mnt/file.txt

Verify that the test file is on the local path:

$ ls /data/docker-volumes/

If you want to load this into other client's /etc/fstab:   /mnt   nfs4    _netdev,auto  0  0

Thank You

That's it. Thanks for reading, follow me on Twitter and say hi! @ruanbekker

Say Thanks!