Question: Docker Swarm can manage two types of storage:

`volume` and `bind`

While `bind` is not suggested by Docker Documentation since it creates a binding between a local directory (on each swarm Node) to a task, the `volume` implementation is not mentioned, so I don't understand how volumes are shared between tasks?

* How does Docker Swarm shares volumes between nodes?
* Where are volumes saved (on a manager? And if there is more than one manager?)
* Is there no problem between nodes if it's running on different machines on different networks?
* Does it create a VPN?

Answer: 
My solution for our locally hosted swarm:
every worker node has mounted an nfs-share, provided by our fileserver on `/mnt/docker-data`. When I define volumes in my services compose files, I set the device to some path under `/mnt/docker-data`, for example:

```
volumes:
  traefik-logs:
    driver: local
    driver_opts:
      o: bind
      device: /mnt/docker-data/services/traefik/logs
      type: none

```

With this solution, docker creates the volume on every node, the service is deployed to and - surprise - there is data already, because it is the same path, which was used by the volume on the other node.

If you take a closer look at the nodes filesystem, you see that mounts to my fileserver mount are created under `/var/lib/docker/volumes`, see here:

```
root@node-3:~# df -h
Dateisystem                                                                                                   Größe Benutzt Verf. Verw% Eingehängt auf
[...]
fs.mydomain.com:/srv/shares/docker-data/services/traefik/logs                                 194G    141G   53G   73% /var/lib/docker/volumes/traefik_traefik-logs/_data

```
by default swarm will always look for local volume driver ,so the best way is to

1. create nfs share i.e. `yum -y install nfs-utils`
2. export it in /etc/exports as below,
`/root/nfshare 192.168.1.0/24(rw,sync,no_root_squash)`
3. open required ports, in my case i did below,
`firewall-cmd --permanent --add-service mountd ; firewall-cmd --permanent --add-service rpc-bind ; firewall-cmd --permanent --add-service nfs ; firewall-cmd --zone=public --permanent --add-port 2049/tcp`
4. mount newly created share on docker worker nodes & then
5. `docker service create --name my-web --replicas 3 -p 80:80 --mount 'type=volume,source=nfshare,target=/usr/share/nginx/html/,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/root/nfshare,"volume-opt=o=addr=192.168.1.8,rw"' nginx:latest`
6. in above example i have created nfshare on 192.168.1.8 host & exported using /etc/exports file
7. started daemon(s)
`systemctl start nfs-server rpcbind & systemctl enable nfs-server rpcbind`
8. exportfs -r to changes take effect
9. /root/nfshare have my own index.html
10.check volume-drive entry carefully , it can be external also & whoa it worked for me
10. for more reference <https://docs.docker.com/storage/volumes/>