Docker Community Forums

Share and learn in the Docker community.

Stack file and images


(Ruliezz) #1

Hi all,

I like to use my own volumes in the stack file for the Swarm.
I created a volume called database. I like to use this volume for my database services.

My stack file:

version: ‘3.1’

services:

wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example

mysql:
image: mariadb
restart: always
volumes:
- database:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: example

But when I run:
docker stack deploy -c wpstack.yml wordpress

it said:
service mysql: undefined volume “database”

So I was wondering, how can you work with volumes in a stack file.

Thanks!


(King Chung Huang) #2

You need to declare the named volume in the volumes section. See volumes.

version: ‘3.1’

services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: example

  mysql:
    image: mariadb
    restart: always
    volumes:
      - database:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: example

volumes:
  database: