Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker 1.12 swarm mode and container volumes

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!

like image 536
Ross Dargan Avatar asked Jul 15 '16 21:07

Ross Dargan


People also ask

Is docker swarm mode deprecated?

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.

Is docker swarm discontinued?

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.

What is the default mode for a swarm?

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.

What is swarm mode in docker?

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.


1 Answers

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 createusing --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.

like image 129
redcalfee Avatar answered Oct 22 '22 15:10

redcalfee