增加了Docker内存大小,现在docker compose无法正常工作

时间:2019-01-02 18:52:50

标签: wordpress docker docker-compose

我在设置中增加了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: {}

2 个答案:

答案 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中运行,它应该可以立即使用。