Best Practices for Setting Up NFS with Docker Swarm

October 20, 2025 3 answers
Asked by TechyNerd42
I've been exploring Docker for a while now, starting with a straightforward Ubuntu VM that managed a few containers. Over time, I've scaled up my setup to about 20 containers, which is a lot to manage, especially during host maintenance when I have to stop everything to update and reboot. Recently, I set up my first Docker Swarm using four Dell machinesโ€”one manager and three workers. Now, I'm faced with the challenge of moving all the configuration volumes that used to be on my local drive to shared storage. I'd prefer not to create individual NFS or SMB shares for each container. Is there a way to create a single SMB/NFS shareโ€”let's call it SwarmConfigโ€”on my NAS that has subfolders for each container, allowing me to mount those subfolders as the config directories for my containers?

Answers

CloudWizard88
For setting up NFS with Docker Swarm, it really depends on your specific needs, but what you've described aligns well with how many setups operate. You would mount the NFS share to each host at the same mount point and then use bind mounts for resources. Here's a basic example: ```yaml volumes: - /swarmconfig/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf ``` This keeps it efficient. However, I understand your concern about connection stabilityโ€”I prefer handling it through configurations so that Docker manages reconnections automatically.
Reply to this answer
NFSMaster3000
If you opt for handling it via the configurations instead of on the host level, it can indeed simplify things. If a connection drops, Docker will typically try to remount it when you restart the container, which is much more convenient than remounting manually.
Reply to this answer
DockerDude99
You can definitely mount your NFS share directly from your NAS into Docker. For example, in your Docker Compose file, you could set it up like this: ```yaml services: app: volumes: - data: volumes: data: driver: local driver_opts: type: "nfs" o: "addr=,rw,noatime,rsize=8192,wsize=8192,tcp,timeo=14,nfsvers=4" device: ":/export/" ``` You can create a subfolder under your export path for each service to store its data. Just be cautious, though; if you're running services using a SQLite database, there's a risk of database corruption with high interactions. Also, it might be beneficial to add another manager to your Swarm for improved stabilityโ€”three managers and five workers work well for me!

NewbieContainer1: Thanks for the insight! Iโ€™m still figuring out Swarm. What happens if my manager goes down, like during maintenance?

DataGuruX: About that SQLite noteโ€”what's the best fix? Should I switch to Postgres or MariaDB, or just deal with the risks?

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions