📚 How to Mount NFS Storage for Docker Containers (Docker Compose Version)

🧩 Purpose

Configure Docker Compose to automatically mount an NFS share as a volume into your containers without manually mounting it on the host.


1. Prerequisites


2. Example docker-compose.yml

yaml

version: '3.8'

services:
  my-app:
    image: my-docker-image
    container_name: my-app
    volumes:
      - my-nfs-storage:/app/data
    ports:
      - "8080:8080"
    restart: unless-stopped

volumes:
  my-nfs-storage:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=192.168.100.11,nfsvers=4,hard,timeo=600,retrans=2"
      device: ":/mnt/hdd-storage/my-nfs-share"

3. Key Configuration Explained

Note: The colon : at the start of device: is important.


4. Deploy the Stack

Run this from the folder where docker-compose.yml is located:

bash

docker-compose up -d

Docker will:


5. Best Practices


6. Summary Table


🚀 Bonus: Troubleshooting NFS Mounts

Common issues:


🎯 Final Tip

For critical workloads:
Use a private network between Docker and the NFS server for security and stability!


✅ Now this will display perfectly in Bookstack 📚
✅ With clean titles, proper spacing, clean code blocks, and info boxes.


Revision #2
Created 27 April 2025 00:26:39 by joliveira
Updated 27 April 2025 02:34:49 by joliveira