Docker Community Forums

Share and learn in the Docker community.

Unable to redeploy a stack using docker compose with persistent volumes within the same collection

docker
ucp

(Adityadani) #1

Hello,

Following is my docker version

Server: Docker Enterprise Edition (EE) 2.0
 Engine:
  Version:          17.06.2-ee-16
  API version:      1.30 (minimum version 1.12)
  Go version:       go1.8.7
  Git commit:       9ef4f0a
  Built:            Thu Jul 26 16:42:11 2018
  OS/Arch:          linux/amd64
  Experimental:     false
 Universal Control Plane:
  Version:          3.0.5
  ApiVersion:       1.30
  Arch:             amd64
  BuildTime:        Thu Aug 30 17:47:03 UTC 2018
  GitCommit:        f588f8a
  GoVersion:        go1.9.4
  MinApiVersion:    1.20
  Os:               linux
 Kubernetes:
  Version:          1.8+
  buildDate:        2018-04-26T16:51:21Z
  compiler:         gc
  gitCommit:        8d637aedf46b9c21dde723e29c645b9f27106fa5
  gitTreeState:     clean
  gitVersion:       v1.8.11-docker-8d637ae
  goVersion:        go1.8.3
  major:            1
  minor:            8+
  platform:         linux/amd64
 Calico:
  Version:          v3.0.8
  cni:              v2.0.6
  kube-controllers: v2.0.5
  node:             v3.0.8

I have created a collection through UCP UI called /System/Blah
I am using Portworx volume driver to provision persistent volumes for my wordpress stack.
Following is the docker compose spec

# Wordpress with MariaDB
version: '3'
services:
  wp:
    image: 'wordpress:latest'
    ports:
       - '8000:80'
    labels:
      app: 'wordpress'
    volumes:
      - 'wp_data:/var/www/html'
    depends_on:
      - 'mariadb'
    environment:
      - WORDPRESS_DB_HOST=mariadb:3306
      - WORDPRESS_DB_NAME=wordpress
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
    deploy:
      placement:
        constraints: [node.role == worker]
      labels:
        com.docker.ucp.access.label: /System/Blah
  mariadb:
    image: 'mariadb:latest'
    ports:
      - '3306'
    labels:
      app: 'mariadb'
    volumes:
      - 'db_data:/var/lib/mysql'
    environment:
      - MYSQL_ROOT_PASSWORD=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
      - MYSQL_DATABASE=wordpress
    deploy:
      placement:
        constraints: [node.role == worker]
      labels:
        com.docker.ucp.access.label: /System/Blah
volumes:
  wp_data:
    driver: pxd
    external: false
    driver_opts:
      size: 5
      repl: 2
      shared: 'true'
      sticky: 'true'
    labels:
      - "com.docker.ucp.access.label=/System/Blah"
  db_data:
    driver: pxd
    external: false
    driver_opts:
      size: 5
      repl: 2
      sticky: 'true'
    labels:
      - "com.docker.ucp.access.label=/System/Blah"

When I deploy this stack using the following command

$ docker stack deploy -c service.yaml portworx-wordpress

Portworx creates the persistent volume and wordpress starts using this volume.

I delete the stack using the following command

docker stack rm portworx-wordpress

Now Portworx has the capability to not delete the volume even if the stack gets deleted.

However if I redeploy the stack I get the following error

failed to create service wordpress_wp: Error response from daemon: located 1 sets of existing volumes named "wordpress_wp_data" with different collection labels. Please make sure all existing volumes with the same name share the same collection or don't have one at all

I understand that if I am redeploying this spec and the volume exists, then the external field under volume should be set to true. But the error that I get is completely different and indicates that the collection is different. Both the volumes have the correct collection and access labels but still docker is complaining with that error.

Here are the labels on the volume that gets created

[
    {
        "Driver": "pxd",
        "Labels": {
            "com.docker.stack.namespace": "wordpress",
            "com.docker.ucp.access.label": "/System/Blah",
            "com.docker.ucp.collection": "<collection_id>",
            "com.docker.ucp.collection.<collection_id>": "true",
            "com.docker.ucp.collection.root": "true",
            "com.docker.ucp.collection.swarm": "true",
            "com.docker.ucp.collection.system": "true"
        },
        "Mountpoint": "/",
        "Name": "wordpress_db_data",
        "Options": {
            "repl": "2",
            "size": "5",
            "sticky": "true"
        },
        "Scope": "global"
    }
]

Is this the right deployment strategy to reuse a persistent volume in a stack using docker-compose?
Any help would be appreciated!