📚 How to Mount NFS Storage on Linux (with Proper Permissions)

Purpose

Mount a remote NFS share on a Linux server for use by Docker containers, ensuring stable operation, correct permissions, and automatic remounting.


1. Install NFS Client on the Server

sudo apt update
sudo apt install nfs-common -y

2. Create a Local Mount Directory

Create a local directory where the NFS share will be mounted:

sudo mkdir -p /srv/nfs-mount
sudo chown $(whoami):$(whoami) /srv/nfs-mount

(You can replace /srv/nfs-mount with your preferred path.)


3. Mount the NFS Share (Manual Test)

Example:

sudo mount -t nfs4 192.168.100.11:/mnt/hdd-storage/my-nfs-share /srv/nfs-mount

4. Verify That the Mount Worked

mount | grep nfs

You should see output like:

192.168.100.11:/mnt/hdd-storage/my-nfs-share on /srv/nfs-mount type nfs4 (...)

5. Make the Mount Persistent (Auto-Mount on Boot)

Edit your /etc/fstab file:

sudo nano /etc/fstab

Add the following line at the bottom:

192.168.100.11:/mnt/hdd-storage/my-nfs-share /srv/nfs-mount nfs4 rw,relatime,hard,proto=tcp,timeo=600,retrans=2,sec=sys,_netdev 0 0

Save and exit (Ctrl+O, Enter, Ctrl+X).


6. Test the fstab Entry Without Rebooting

sudo mount -a

No errors = success! ✅


7. Using the NFS Mount with Docker

When running your containers, bind-mount the NFS storage into the container:

docker run -d \
  --name my-container \
  -v /srv/nfs-mount:/app/data \
  my-docker-image

This will allow your Docker containers to directly access the NFS storage.


✅ Summary


🛠️ Useful Commands


🦠 Additional Notes


Revision #2
Created 27 April 2025 00:41:23 by joliveira
Updated 27 May 2025 04:14:48 by joliveira