How does Docker Swarm implement volume sharing?

alessandro308 picture alessandro308 · Dec 11, 2017 · Viewed 60.3k times · Source

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

Bret Fisher picture Bret Fisher · Dec 13, 2017

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.