Docker撰写MySQL卷无效无效规范

时间:2019-03-17 07:34:25

标签: docker-compose volumes

我正在使用服务3,以下是mycode,

我试图在环境中添加var- COMPOSE_CONVERT_WINDOWS_PATHS:1

它仍然显示错误:

错误:对于db-on-docker-ms_mysql-dev_1无法为服务mysql-dev创建容器:无效的卷规范:'/ c / Dockerfile / db-on-docker-ms:/ var / lib / mysql在卷下:rw'

version: '3'
services:
  mysql-dev:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: blogapp
  ports:
    - "3308:3306"
  volumes:
    - /c/Dockerfile/db-on-docker-ms:/var/lib/mysql

我的Docker版本:18.09.2

2 个答案:

答案 0 :(得分:1)

我认为您需要在命令行中设置COMPOSE_CONVERT_WINDOWS_PATHS环境变量

$ export COMPOSE_CONVERT_WINDOWS_PATHS=1

然后更改volumes配置

version: '3'
services:
  mysql-dev:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: blogapp
  ports:
    - "3308:3306"
  volumes:
    - c:\Dockerfile\db-on-docker-ms:/var/lib/mysql

运行docker compose

$ docker-compose up

或者您可以尝试像这样设置volumes

version: '3'
services:
  mysql-dev:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: blogapp
  ports:
    - "3308:3306"
  volumes:
    - //c/Dockerfile/db-on-docker-ms:/var/lib/mysql

运行docker compose

$ docker-compose up

答案 1 :(得分:0)

首先感谢Misantorp的回答!

我终于弄清楚了如何在Windows容器中做到这一点

卷路径应为:

volumes:
  - C:\Dockerfile\db-on-docker-ms:/var/lib/mysql

在powershell中运行命令:

COMPOSE_CONVERT_WINDOWS_PATHS = 0

然后运行:

docker-compose up