Build a Home NFS Server with Docker

Deploy a lightweight NFS server in minutes using Docker and the NFSServer project. Perfect for home labs, developers, and GoMount users.

1Why a Home NFS Server?

NFS (Network File System) is a fast, lightweight protocol for sharing files across a local network. Unlike SMB, which carries a lot of Windows compatibility overhead, NFS is lean and performs exceptionally well on Linux-based systems and macOS. If you want a simple file share for backups, media streaming, or development work, a Docker-based NFS server is one of the quickest ways to get started.

This guide uses the itsthenetwork/nfs-server-alpine Docker image, a minimal Alpine Linux-based NFS server that requires almost no configuration. You will have a working share in under five minutes.

2Prerequisites

Before you begin, make sure you have:

  • A Mac, Linux PC, or NAS device with Docker installed
  • Docker Engine 20.10 or later
  • A local directory you want to share (e.g., /data/nfs/share)
  • Your Mac and the Docker host on the same local network

Running Docker on macOS? Use Docker Desktop. It is free for personal use and provides a seamless experience. Download it from docker.com.

3Install Docker

If Docker is not already installed, download and install Docker Desktop for your platform. After installation, verify it works by running:

docker --version

You should see a version string like Docker version 24.0.7, build afdd53b. If you get a "command not found" error, make sure Docker Desktop is running and the CLI is in your PATH.

4Create the NFS Server

Create a local directory that will hold your shared files. This directory lives on your Docker host and is mounted into the container.

mkdir -p /data/nfs/share

Now run the NFS server container with a single Docker command:

docker run -d \
  --name nfs-server \
  --privileged \
  -p 2049:2049 \
  -p 2049:2049/udp \
  -v /data/nfs/share:/data/nfs/share \
  -e SHARED_DIRECTORY=/data/nfs/share \
  -e ALLOWED_HOSTS=0.0.0.0/0 \
  itsthenetwork/nfs-server-alpine:latest

What this command does:

  • -d — Runs the container in detached (background) mode
  • --privileged — Required for the container to run the NFS kernel module
  • -p 2049:2049 — Maps TCP port 2049 from host to container
  • -p 2049:2049/udp — Maps UDP port 2049 as well (NFS uses both)
  • -v /data/nfs/share:/data/nfs/share — Mounts your local directory into the container
  • -e SHARED_DIRECTORY=/data/nfs/share — Tells the container which directory to export
  • -e ALLOWED_HOSTS=0.0.0.0/0 — Allows any host on your network to connect

Security note: ALLOWED_HOSTS=0.0.0.0/0 opens the share to any device that can reach port 2049. For a home network behind a router, this is usually fine. For stricter control, replace it with your local subnet, e.g., 192.168.1.0/24.

5Configure the Share

The NFSServer image handles export configuration automatically via environment variables. You already set the two most important ones: SHARED_DIRECTORY and ALLOWED_HOSTS.

You can also pass EXTRA_OPTS to add custom NFS export options. For example, to enable asynchronous writes for better performance:

-e EXTRA_OPTS="rw,async,no_root_squash"

Common export options include:

  • rw — Read and write access
  • ro — Read-only access
  • async — Faster writes (data may not hit disk immediately)
  • sync — Slower but safer writes
  • no_root_squash — Allows root users on clients to have root access
  • all_squash — Maps all users to anonymous

Default behavior: Without EXTRA_OPTS, the container exports with rw,sync,no_subtree_check,no_root_squash. This is a reasonable default for home use.

6Verify the Server

Check that the container is running:

docker ps

You should see nfs-server in the list with status Up. Next, verify the export is visible from the host itself:

showmount -e localhost

Expected output:

Export list for localhost:
/data/nfs/share 0.0.0.0/0

If you see the export path, your NFS server is live and ready for connections.

7Connect from macOS

Before using GoMount, test the connection manually from your Mac to confirm everything is reachable.

First, find the IP address of your Docker host. If you are running Docker on the same Mac, use localhost or 127.0.0.1. If Docker is on another machine (a Raspberry Pi, Linux server, or NAS), use that machine's local IP address, e.g., 192.168.1.50.

Mount the share temporarily using macOS's built-in mount_nfs command:

sudo mount -t nfs -o vers=4,tcp,noresvport 192.168.1.50:/data/nfs/share /Volumes/NFSShare

Then open Finder and look under Locations for NFSShare. You should be able to read and write files.

When finished testing, unmount cleanly:

sudo umount /Volumes/NFSShare

Why vers=4,tcp,noresvport? These options tell macOS to use NFSv4 over TCP with non-reserved ports. This combination offers the best compatibility with modern Docker-based NFS servers and avoids common macOS mount failures.

8Connect via GoMount

Now that your NFS server is running and reachable, add it to GoMount for automatic mounting.

  1. Open GoMount Settings and switch to the NAS Config tab.
  2. Click the + button to add a new device.
  3. Set Protocol to NFS.
  4. Enter the Address of your Docker host (e.g., 192.168.1.50).
  5. Enter the Share path: /data/nfs/share.
  6. Leave Username and Password empty unless you configured authentication on the server.
  7. Save and go to the Rules tab to set your network trigger.

GoMount will now automatically mount the NFS share whenever your Mac enters your trusted network. For a detailed walkthrough of the mount process and protocol comparison, see our GoMount Docker NFS Server Guide.

New to GoMount? If you have not installed it yet, start with our Getting Started guide for installation and first-time setup instructions.

9Advanced Configuration

Persistent Data with Docker Volumes

Instead of bind-mounting a host directory, you can use a named Docker volume for better portability:

docker volume create nfs-data

docker run -d \
  --name nfs-server \
  --privileged \
  -p 2049:2049 \
  -p 2049:2049/udp \
  -v nfs-data:/data/nfs/share \
  -e SHARED_DIRECTORY=/data/nfs/share \
  -e ALLOWED_HOSTS=0.0.0.0/0 \
  itsthenetwork/nfs-server-alpine:latest

Running on a Raspberry Pi

The itsthenetwork/nfs-server-alpine image supports ARM64 out of the box. On a Raspberry Pi 4 or 5, just run the same command. Docker will automatically pull the correct architecture variant.

Multiple Shares

To export multiple directories, run multiple containers on different ports or use a custom /etc/exports file. For most home users, a single share is sufficient. If you need more, create additional containers:

docker run -d --name nfs-media --privileged -p 2050:2049 ...
docker run -d --name nfs-backup --privileged -p 2051:2049 ...

10Troubleshooting

Container fails to start

  • Make sure Docker is running: docker info
  • Check if port 2049 is already in use: lsof -i :2049
  • Ensure the shared directory exists on the host before starting the container

Mac cannot mount the share

  • Verify the Docker host IP is correct and both devices are on the same network
  • Try pinging the host: ping 192.168.1.50
  • Check firewall rules on the Docker host — port 2049 must be open
  • Use showmount -e 192.168.1.50 from the Mac to verify the export is visible

Permission denied errors

  • Check file ownership inside the shared directory. The container runs as root by default.
  • If you mapped a local directory, ensure the directory permissions allow read/write access.
  • Add no_root_squash to EXTRA_OPTS if root access is required.

Slow transfer speeds

  • Switch from sync to async writes: -e EXTRA_OPTS="rw,async"
  • Use a wired Ethernet connection instead of Wi-Fi
  • Ensure your router supports Gigabit Ethernet

Need more help? Read our troubleshooting guide for general NAS mount issues. If you are comparing protocols, see NFS vs SMB on macOS. For a deeper dive into GoMount's network trigger rules, check out Auto-Mount NAS When Your Mac Comes Home.

Ready to automate your NAS?

Download GoMount free and upgrade to Pro anytime for unlimited devices and full read/write access.

Download for macOS