Docker for Windows -无法装载本地卷,没有此类文件或目录

6jjcrrmo  于 2022-12-03  发布在  Docker
关注(0)|答案(1)|浏览(204)

我遇到了与此处相同的问题Docker - failed to mount local volume, no such file or directory

docker-compose --verbose up -d
[+] Running 0/0
 - Container brickchart-mysql-1  Creating                                                                                                                                                                                          0.0s 
Error response from daemon: failed to mount local volume: mount 
.docker/mysql/data:/var/lib/docker/volumes/brickchart_db_volume/_data, 
flags: 0x1000: no such file or directory

下面是我的docker-compose.yml文件:

version: '3.9'

services:
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db_name
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_password
    ports:
      - "3306:3306"
    volumes:
      - db_volume:/var/lib/mysql:delegated

volumes:
  db_volume:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: ./.docker/mysql/data

我安装了最新的Docker Desktop:

我还测试了旧版本:第4.14.0节、第4.12.0节和第4.10.1节中所述。
我知道docker-compose文件被转换成了docker命令。一个verbose标志会有很大帮助。不幸的是,verbose标志似乎不存在:https://github.com/docker/compose/issues/1640
如果我能看到

volumes:
  - db_volume:/var/lib/mysql:delegated

将被转换为Docker命令。
有没有人对这个问题有什么建议?

eivgtgni

eivgtgni1#

这个Volume binding using docker compose on Windows帮助我解决了我的问题。
它必须是主机系统的绝对路径。
所以我的解决方案就是现在。

version: '3.9'

services:
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db_name
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_password
    ports:
      - "3306:3306"
    volumes:
      - db_volume:/var/lib/mysql:delegated

volumes:
  db_volume:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: ${PATH_TO_DB_DATA}

相应的.env文件包含变量PATH_TO_DB_DATA。例如:

PATH_TO_DB_DATA='/d/path/to/my-project/.docker/mysql/data/'

相关问题