我在设置中增加了Windows CPU和内存大小的泊坞窗,并重新启动,然后尝试在项目上运行docker-compose up -d
并收到以下错误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.
这是我的docker compose文件,在我增加了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: {}
答案 0 :(得分:1)
您可以就地使用Docker命名卷并在多个容器中共享该名称,这也将使调试更加容易
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:
答案 1 :(得分:1)
如果从WSL运行,则可以将您的docker-compose.yml
更改为以下内容
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
注意前缀/mnt/c
而不是C:/
另一种方法是使用相对路径或创建命名卷,例如:
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: {}
如果从Powershell中运行,它应该可以立即使用。