简体   繁体   English

Windows 主机 Docker + WSL - 卷安装问题

[英]Windows Host Docker + WSL - Volume mounting issue

thx to corona - most of us working from home and due to some convenience, i want to use my windows machine that i have here at home.感谢电晕 - 我们大多数人在家工作,由于一些方便,我想使用我在家里的 windows 机器。

I do run Win10 with DockerDesktop Version 2.3.0.3 with Engine running on Version 19.03.8.我确实使用 DockerDesktop 版本 2.3.0.3 运行 Win10,引擎在版本 19.03.8 上运行。 What I am doing is exposing the docker deamon on localhost in order to use it from my WSL (Version 1, not 2) installed Ubuntu.我正在做的是在本地主机上公开 docker 守护程序,以便从我安装的 Ubuntu 的 WSL(版本 1,而不是 2)中使用它。 Docker itself works, I can pull images and do basic stuff. Docker 本身可以工作,我可以拉图像并做一些基本的事情。 But I am facing issues when mounting volumes:-/但是我在安装卷时遇到了问题:-/

When I try to run my docker-compose up command, it fails with the following error:当我尝试运行 docker-compose up 命令时,它失败并出现以下错误:

ERROR: for my-service  Cannot start service my-service: error while mounting volume '/var/lib/docker/volumes/someDir/_data': failed to mount local volume: mount /home/myUser/myLocalDirectory:/var/lib/docker/volumes/someDir/_data, flags: 0x1000: no such file or directory

The directory /home/myUser/myLocalDirectory does exist.目录/home/myUser/myLocalDirectory确实存在。 Directory /var/lib/docker/volumes/someDir/_data does not exist on my WSL "host".我的 WSL“主机”上不存在目录/var/lib/docker/volumes/someDir/_data There is only a /var/lib/docker-engine/... folder, which is obviously not the one i am looking for:-/只有一个/var/lib/docker-engine/...文件夹,这显然不是我要找的文件夹:-/

My working path is /mnt/e/projects/myDockerProject - but i also tried to mount/bind the folder/harddrive like shown here .我的工作路径是/mnt/e/projects/myDockerProject - 但我也尝试安装/绑定文件夹/硬盘驱动器,如此处所示

All does not work and i am really stuck - do you have any suggestions/explanations?一切都不起作用,我真的被困住了——你有什么建议/解释吗?

When I run a linux container using Docker for Windows, I bind-mount c:/the/windows/path:/desired/path/in/the/container . When I run a linux container using Docker for Windows, I bind-mount c:/the/windows/path:/desired/path/in/the/container .

There's a lot of layers here:这里有很多层:

         ___ WSL
        /
Windows
        \___ Docker Linux VM -- Containers

Under "normal" circumstances (linux host with linux containers), you bind mount a local directory.在“正常”情况下(带有 linux 容器的 Linux 主机),您绑定挂载本地目录。 In the diagram above, that would correspond to a directory in the Docker Linux VM.在上图中,这将对应于 Docker Linux VM 中的目录。 But Docker for Windows allows us to specify a windows path instead.但是 Windows 的 Docker 允许我们指定 windows 路径。

When you throw WSL into the mix, things get a bit muddier.当您将 WSL 加入其中时,事情会变得更加混乱。 Within WSL, /home is already some kind of magic that isn't shown to be directly linked to the c drive:在 WSL 中, /home已经是某种魔法,它没有显示为直接链接到c驱动器:

root@MyPcName:~# df
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         498557588 390255608 108301980  79% /
root           498557588 390255608 108301980  79% /root
home           498557588 390255608 108301980  79% /home
data           498557588 390255608 108301980  79% /data
cache          498557588 390255608 108301980  79% /cache
mnt            498557588 390255608 108301980  79% /mnt
none           498557588 390255608 108301980  79% /dev
none           498557588 390255608 108301980  79% /run
none           498557588 390255608 108301980  79% /run/lock
none           498557588 390255608 108301980  79% /run/shm
none           498557588 390255608 108301980  79% /run/user
cgroup         498557588 390255608 108301980  79% /sys/fs/cgroup
C:\            498557588 390255608 108301980  79% /mnt/c

/home obviously corresponds to C:\Users , but you can't tell from the output of df or the contents of /proc/mounts or /etc/fstab . /home显然对应于C:\Users ,但是您无法从df的 output 或/proc/mounts/etc/fstab的内容中分辨出来。

I would suggest that you try the following:我建议您尝试以下方法:

  1. Specify the windows path: C:/Users/myUser/myLocalDirectory:/desired/path/in/the/container指定 windows 路径: C:/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  2. Specify the WSL path starting with the "base" windows drive: /mnt/c/Users/myUser/myLocalDirectory:/desired/path/in/the/container指定以“基础”windows 驱动器开头的 WSL 路径: /mnt/c/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  3. If neither of those work, launch docker-compose up from a DOS or powershell prompt, and use the windows path as in #1 above如果这些都不起作用,请从 DOS 或 powershell 提示符启动docker-compose up ,并使用 windows 路径,如上面的#1

I was facing a similar issue:我遇到了类似的问题:

[+] Running 0/1
⠹ Container mysqllocal  Creating                    0.2s
Error response from daemon: failed to mount local volume: mount
/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/0728c21eeaba2a2ed809c50fb993ad2a7f00d011276b110991eafe61e99bbd25:/var/lib/docker/volumes/mysql-volume/_data, flags: 0x1000: no such file or directory

In my case after the docker volume prune the docker volume ls shows no volumes but the docker desktop interface still have volumes listed.在我的情况下, docker volume prunedocker volume ls显示没有卷,但 docker 桌面界面仍然列出卷。

The issue was fixed after removing the volumes using the docker desktop interface.使用 docker 桌面界面删除卷后,此问题已得到修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM