When configuring /etc/fstab to mount an NFS share that will be used by Docker, it's important to choose the right options for reliability, performance, and compatibility with Docker volumes.
Here’s a recommended fstab entry for mounting an NFS share to be used by Docker:
<server_ip>:/path/to/nfs/share /mnt/local/mount/path nfs defaults,_netdev,noatime,nofail 0 0
🔧 Breakdown of Options:
| Option | Purpose |
|---|
defaults | Uses default settings: rw, suid, dev, exec, auto, nouser, async |
_netdev | Tells the system this is a network device; prevents boot issues if the mount is not available at boot time |
noatime | Improves performance by disabling access time updates (useful for Docker and containers) |
nofail | Allows the system to boot even if the mount fails (optional but useful) |
nfsvers=4 or vers=4 | Forces NFS version 4 (often preferred); you can use nfsvers=3 if needed |
soft or hard | See below for explanation |
timeo=14 | Time (in tenths of a second) before retrying a request |
intr | Allows NFS requests to be interrupted if the server goes down (deprecated in newer kernels) |
✅ Example with NFSv4:
192.168.1.10:/exports/docker_data /mnt/nfs/docker nfs defaults,_netdev,noatime,nofail,nfsvers=4 0 0
🐳 Why This Matters for Docker
Docker needs consistent and reliable access to volumes. Mounting via /etc/fstab ensures that the volume is mounted early in the boot process and available when Docker starts.
- Use a stable mount point like
/mnt/nfs/docker or /opt/docker-data.
- You can then create Docker volumes pointing to directories inside that mount.
- Ensure permissions are correct on the NFS share so Docker has access.
📌 Tips:
💡 Bonus: Using Docker Named Volumes with NFS
Once the NFS share is mounted locally (e.g., at /mnt/nfs/docker), you can configure Docker to use it:
Option 1: With docker run
docker run -d \
--name mycontainer \
-v /mnt/nfs/docker/myvol:/target/path \
myimage
Option 2: Create a Docker named volume
docker volume create \
--driver local \
--opt type=nfs \
--opt o=addr=192.168.1.10,rw,nfsvers=4 \
--opt device=:/exports/docker_data \
my-nfs-volume
Then use it:
docker run -d --name mycontainer -v my-nfs-volume:/data myimage
Let me know if you want a full example of setting up NFS + Docker together!