compose: Compose with Swarm can't locate named volumes

I’m having trouble running simple compose task on Swarm:

version: "2"
services:
  elastic-01:
    image: elasticsearch:2
    environment:
      SERVICE_NAME: elastic
    ports:
      - 9200:9200
    volume_driver: flocker
    volumes:
      - 'data_01:/usr/share/elasticsearch/data'

  elastic-02:
    image: elasticsearch:2
    ports:
      - 9201:9200
    volume_driver: flocker
    volumes:
      - 'data_02:/usr/share/elasticsearch/data'
    command: elasticsearch --discovery.zen.ping.unicast.hosts=elastic-01

volumes:
  data_01:
    external:
      name: "es_data_01"

  data_02:
    external:
      name: "es_data_02»

Running docker-compose up I receiving following error:

eric@iMac-Eric /V/D/W/s/a/elk-swarm> docker-compose up
ERROR: Volume es_data_01 declared as external, but could not be found. Please create the volume manually using `docker volume create --name=es_data_01` and try again.
eric@iMac-Eric /V/D/W/s/a/elk-swarm> 

At the same time time, docker command works ok:

eric@iMac-Eric /V/D/W/s/a/elk-swarm> docker run -it --rm --volume-driver flocker -v es_data_01:/data ubuntu
root@96b0c807c46f:/# ls /data
elasticsearch  test1
root@96b0c807c46f:/# exit
eric@iMac-Eric /V/D/W/s/a/elk-swarm> 

Also, here is output from volume list:

eric@iMac-Eric /V/D/W/s/a/elk-swarm> docker volume ls
DRIVER              VOLUME NAME
local               swarm-node-05a.cybertonica.aws/3f7c3fb82a73f539f318e14b3f260b3cc32d50836b544d5db4572d202366d16c
flocker             es_data_02
flocker             es_data_01
local               swarm-node-06a.cybertonica.aws/a5a94eb763e09f6cf49a2b95dddbd7351a1e1074a690b3553311690120a4dc18
flocker             es_data_01
flocker             es_data_02
eric@iMac-Eric /V/D/W/s/a/elk-swarm> 

If I run docker-compose against any single docker node, everything works ok too.

What am I doing wrong here?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 36

Most upvoted comments

@gittycat yes. as I suspected, there are issues with local named volumes as well. My patch for the Swarm is related only to non-local volumes.

I think we need to open a separate issue about local volumes and swarm.

TBH, there are caveats in how Swarm treats volumes on docker engines. (all examples below are run agains a swarm manager)

  1. docker volume ls:
DRIVER              VOLUME NAME

No Volumes yet. 2) docker volume create --name=v1

DRIVER              VOLUME NAME
local               swarm-node-06a.cybertonica.aws/v1
local               swarm-node-05a.cybertonica.aws/v1

By default, docker volume create creates a volume on all engines. 3) docker volume create --name=swarm-node-06a.cybertonica.aws/v2

DRIVER              VOLUME NAME
local               swarm-node-06a.cybertonica.aws/v1
local               swarm-node-05a.cybertonica.aws/v1
local               swarm-node-06a.cybertonica.aws/v2

Here we explicitly tell where to create a volume. Now let’s try to get info about our volumes: 4) docker volume inspect v2

[
    {
        "Name": "v2",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/v2/_data"
    }
]
  1. docker volume inspect v1
[]
Error: No such volume: v1

Why? The problem here is that really we have 2 different volumes named v1 - v1 on node swarm-05a and on node swarm-06a. So swarm can’t determine which one we need and therefore returns nil. But! 6) docker volume inspect swarm-node-05a.cybertonica.aws/v1

[
    {
        "Name": "v1",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/v1/_data"
    }
]

Now back to docker-compose. In version 2, looks like it tries to locate volume by its name, and fails as there several volumes with that name. And its quite logical, since Swarm can’t figure out which volume should be attached to your container. Naive solution for this issue would be to add qualified volume names support in docker-compose, but, unfortunately, they are not allowed yet:

version: '2'

services:
  app:
    image: alpine:3.3
    volumes:
      - vault:/secrets
    command: ls -al /secrets

volumes:
  vault:
    external:
      name: "swarm-node-05a.cybertonica.aws/v1»

And running it:

eric@iMac-Eric /V/D/W/g/s/c/p/d/t2> docker-compose up 
Recreating t2_app_1
ERROR: 500 Internal Server Error: create swarm-node-05a.cybertonica.aws/v1: volume name invalid: "swarm-node-05a.cybertonica.aws/v1" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed
eric@iMac-Eric /V/D/W/g/s/c/p/d/t2> 

@pbaiz-amey an other good option is EMC Rex-ray. IMO, its easier in setup:

  • single binary
  • no need for central service
  • simple, clear CLI

But, of course, YMMV

@everett-toews thanks for pointing to that issue. Very interesting. Maybe I should post my comment there?