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: 
What you're asking about is a common question. Volume data and the features of what that volume can do are managed by a volume driver. Just like you can use different network drivers like `overlay`, `bridge`, or `host`, you can use different volume drivers.

Docker and Swarm only come with the standard `local` driver out of the box. It doesn't have any awareness of Swarm, and it will just create new volumes for your data on whichever node your service tasks are scheduled on. This is usually not what you want.

You want a 3rd party driver plugin that is Swarm aware, and will ensure the volume you created for a service task is available on the right node at the right time. Options include using "Docker for AWS/Azure" and its included [CloudStor](https://docs.docker.com/docker-for-azure/persistent-data-volumes/) driver, or the popular open source [REX-Ray](https://rexray.readthedocs.io/en/stable/) solution.

There are lots of 3rd party volume drivers, which you can find on the [Docker Store](https://store.docker.com/search?category=volume&q=&type=plugin).
My solution for AWS EFS, that works:

1. [Create EFS](https://docs.aws.amazon.com/efs/latest/ug/gs-step-two-create-efs-resources.html) (don't forget to open NFS port 2049 at security group)
2. Install nfs-common package:

`sudo apt-get install -y nfs-common`
3. Check if your efs works:

```
mkdir efs-test-point
sudo chmod go+rw efs-test-point
```

```
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport [YOUR_EFS_DNS]:/ efs-test-point
```

```
touch efs-test-point/1.txt
sudo umount efs-test-point/
ls -la efs-test-point/
```

> 
> directory must be empty
> 
> 
> 

```
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport [YOUR_EFS_DNS]:/ efs-test-point
```

`ls -la efs-test-point/`

> 
> file 1.txt must exists
> 
> 
>
4. Configure docker-compose.yml file:

```
services:
  sidekiq:
    volumes:
      - uploads_tmp_efs:/home/application/public/uploads/tmp
  ...
volumes:
  uploads_tmp_efs:
    driver: local
    driver_opts:
      type: nfs
      o: addr=[YOUR_EFS_DNS],nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2
      device: [YOUR_EFS_DNS]:/
```