Reputation: 1545
I increased my docker for windows CPU and memory size in settings, and it did a restart, then I tried to run docker-compose up -d
on my project and I got the following error ERROR: Named volume "C:/Users/andersk/sites/sylr:/var/www/html" is used in service "wordpress" but no declaration was found in the volumes section.
Here is my docker compose file, it was working just fine up until I increased those settings in the docker.
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "2000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
- C:/Users/andersk/sites/sylr:/var/www/html
volumes:
db_data: {}
Upvotes: 1
Views: 159
Reputation: 4202
If ran from WSL one can change your docker-compose.yml
to the following
version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "2000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
- /mnt/c/Users/andersk/sites/sylr:/var/www/html
Note the prefix /mnt/c
instead of C:/
Another method would be to use a relative path or create a named volume like:
version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "2000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
- some_volume_name:/var/www/html
volumes:
some_volume_name: {}
If ran from Powershell it should work just out of the box.
Upvotes: 1
Reputation: 1897
You can use docker named volume in place and share that name across multiple containers, it would also make debugging easier
version: "3"
services:
db:
image: db
volumes:
- data-volume:/var/lib/db
backup:
image: backup-service
volumes:
- data-volume:/var/lib/backup/data
volumes:
data-volume:
Upvotes: 1