Docker Swarm: How to handle persistent data (e.g. database)

Viewed 2406

I have 3-node docker swarm mode cluster (1 manager and 2 workers).

Now I want to deploy a mongodb service to the cluster and I would like to store the database on a persistent storage that I've mounted under /mnt/data. So basically I want the service to use my mounted storage inside each containers /db/data.

How do I achieve this?

I made myself familiar with docker service create --mount but

  • I am not sure if I should use a volume or a bind-mount ?
  • if I choose volume how can I tell docker to store this volume on /mnt/data

To couple the mongodb services to a specific node (where the storage is mounted) I added a label to the corresponding node and start the docker service with a constraint.

1 Answers
Related