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...
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.
As of the 19.03 release, there is now an option to limit the number of replicas per node to avoid multiple replicas accessing the same volume:
With this added to the
service create
command, the next step will be adding a placement preference in the compose file to supportdocker stack deploy
.