I’m looking into using the new docker 1.12 swarm mode but am at a loss when it comes to the high availability features in combination with stateful containers (like a database container).
Ordinarily I would use a volume to store the data for a database on a node which would be found again when I recreate a container on the same node (a named volume).
Now consider the following situation:
I have a docker swarm mode cluster of 1 node and start a mongo service with a mount like this:
docker service create --mount type=volume,source=mongodata,target=/data/db,volume-driver=local --replicas 1 -p 28001:27017 --name mongomain mongo --auth
The cluster will fire up a service with a volume (now called mount) which works just fine, remove and recreate the service and the data will be there.
However, what would happen if I create this service on a multi node cluster? If the first node drops and the cluster fires up a new task on a different node, I presume it won’t have the same volume there. So I will have lost my data.
And what if I’d like to use replication? a swarm with 3 nodes and 3 instances of mongodb in replication mode. Is that even possible with the redistribution of tasks done by swarm mode?
I’m currently thinking the only real solution would be to just running 3 classic containers on these nodes and just use swarm mode for my stateless (frontend etc.) tasks.
Is there a better way to do this using the swarm mode?