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?
3 Answers
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!
About that SQLite note—what's the best fix? Should I switch to Postgres or MariaDB, or just deal with the risks?
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.
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.

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