I have several container that require state - I will only ever set the scale to 1, but I would like it so that no matter which host they start on the volume would be shared.
I'm guessing I need to use a network mount to achieve this (which is fine), but how on earth do I configure the volume using docker swarm 1.12?
I know I can use docker volume create, and I think I might need to specify a driver but I'm struggling to find a single example of this!
Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.
Important note: At the time of this writing, Docker Swarm is not dead. It is included in the Docker Community edition and Docker has not announced plans to deprecate it.
By default Docker Swarm uses a default address pool 10.0. 0.0/8 for global scope (overlay) networks. Every network that does not have a subnet specified will have a subnet sequentially allocated from this pool.
Docker Engine 1.12 introduces swarm mode that enables you to create a cluster of one or more Docker Engines called a swarm. A swarm consists of one or more nodes: physical or virtual machines running Docker Engine 1.12 or later in swarm mode. There are two types of nodes: managers and workers.
docker service create --mount ...
provides two options for persistent data; bind mounts and named volumes. Bind mounts persist on the host created so will not work for you since not shareable.
Named volumes can be created using docker volume create
or created implicitly as part of docker service create
using --mount option, e.g.
$ docker volume create -d --driver cio --name cassandradb --opt profile=CASSANDRA
$ docker service create \
--mount source=cassandradb,target=/var/lib/cassandra,volume-driver=cio \
--replicas 1 \
--name cassandra \
cassandra
docker service create
defaults to named volumes so the type is not specified in the example. The volume driver supports portable volumes. Other volume drivers such as RexRay or Flocker also support portable volumes. Here is an article with examples on RexRay.
There are also --mount options for volume labels and volume options. You can pickup more info on bind mounts and named volumes.
Additional example using the Storidge volume driver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With