Docker swarm and volumes

cassandradockerdocker-swarm

Considering Docker 1.12. I understand that volumes are not per say portable across the swarm and that solutions like Flocker would be better for larger clusters.

Nevertheless, is the option I describe below acceptable for my setup?

Setup
A swarm with 3 nodes runnin Docker 1.12.latest from the experimental branch.

Goal
Run a nice but small Cassandra cluster.

Problem
I want to decouple the stateful part of the service (the data volume) from the stateless Cassandra daemons.

Proposed solution
Create a named volume manually on each node with the same name on each node.
Use docker service create --name cassandra --replicas 3 --mount type=volume,source=cassandra_data,target=/usr/var/cassandra

My understanding is that one replica of the Cassandra will be run and every node, each one referring a local named volume with the same name.

Would this work?
Do I need to specify a constraint to make sure there is at max 1 replica per node of the swarm?

Edit: reading the doc, it seems I should use --mode=global instead of replicas=3 to run exactly 1 replica per node of the swarm. Which makes a lot of sense…

Best Answer

Yes this does work, and using the global flag will be a better option to prevent any conflicts. I have run a similar model to this with MongoDB as a test and worked perfectly.

Related Topic