How to Mount Unaspro NFS Shares as Docker Volumes
If you're using a Ubiquiti UNAS Pro and want to use its NFS feature to store Docker container data on shared drives, this guide will walk you through the process.
Prerequisites
- A Linux server with Docker installed
- A Ubiquiti UNAS Pro
- Basic understanding of Docker
Step 1: Verify Your NFS Exports
Before attempting to mount anything, it's crucial to verify which paths your Ubiquiti UNAS Pro is actually exporting. The Settings -> Services dashboard might display a mount command like:
sudo mount -t nfs 10.1.1.1:/var/nfs/shared/[Shared Drive Name] /mnt
However, this exported path may not work inside the Docker container.
Use Case: Storing Docker Container Volume Data on Ubiquiti UNAS Pro
Scenario:
A user has a Ubiquiti UNAS Pro and a Linux-based server running Docker. They want to store Docker container volume data on the Ubiquiti UNAS Pro using NFS to ensure centralized storage, easy backups, and better data persistence across container restarts.
Solution:
- Enable NFS on the Ubiquiti UNAS Pro and configure exported shared drives.
- Configure Docker volumes to use the mounted NFS path for persistent storage.
Benefit:
This setup ensures that container data is stored securely on the Ubiquiti UNAS Pro, making it easier to manage, back up, and access from multiple servers if needed.
Setup
Make sure that you have enabled the NFS share in the Ubiquiti UNAS Pro settings - service UI and that the both machines Ubiquiti UNAS Pro and Linux server are at the same network.
Login to your server by SSH and run this command to see the available NFS shares, :
showmount -e YOUR_UNASPRO_IP
For example:
showmount -e 10.1.1.1
This might return something like:
Export list for 10.1.1.1:
/volume1/.srv/.unifi-drive/[Shared Drive Name]/.data [YOUR_LINUX_SERVER_IP]
The [YOUR_LINUX_SERVER_IP] comes from the Ubiquiti UNAS Pro NFS settings see the Image 2
Important: Note the exact path shown here. This is the actual path you'll need to use, not what might be shown in the Ubiquiti UNAS Pro dashboard.
Step 2: Create a docker-compose.yml File on your Linux server
Create a docker-compose.yml file with the following content:
version: '3'
services:
your-service:
image: ubuntu # or any image you prefer
command: tail -f /dev/null # Keeps the container running
volumes:
- nfs-data:/mount/point
# Add other container configurations as needed
volumes:
nfs-data:
driver: local
driver_opts:
type: nfs
o: "addr=YOUR_UNASPRO_IP,rw,nfsvers=3,nolock"
device: ":/EXACT_PATH_FROM_SHOWMOUNT"
Replace:
- YOUR_UNASPRO_IP with your Unaspro server IP (e.g., 10.10.1.1)
- /EXACT_PATH_FROM_SHOWMOUNT with the path you got from the showmount command (e.g., /volume1/.srv/.unifi-drive/[Shared Drive Name]/.data)
- /mount/point with where you want the files to appear inside your container
Step 3: Start Your Container
Run the following command to start your container:
docker compose up -d
Step 4: Verify the Mount
Check if your container is running:
docker compose ps
If it's running, you can access the container and verify the mount:
docker compose exec [Your Docker Container name] bash
# Once inside the container, check the mount:
df -h
# or
mount | grep nfs
# or
ls -la /mount/point
Try creating a test file to verify write access:
echo "Hello from Docker" > /mount/point/test_file.txt
Common Issues and Solutions
[TODO]
Conclusion
Mounting Unaspro NFS shares as Docker volumes provides a convenient way to have persistent storage for your containers. The key is to verify the exact export path and use the correct mount options.
This approach allows you to:
- Share data between containers
- Persist data beyond container lifecycles
- Leverage your existing Unaspro storage infrastructure
Have you used NFS with Docker? Share your experiences in the comments!