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?
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 driver, or the popular open source REX-Ray solution.
There are lots of 3rd party volume drivers, which you can find on the Docker Store.