gpt4 book ai didi

docker - Windows Host Docker + WSL - 卷安装问题

转载 作者:行者123 更新时间:2023-12-02 19:47:52 25 4
gpt4 key购买 nike

感谢电晕 - 我们大多数人在家工作,由于一些方便,我想使用我在家里的 Windows 机器。
我确实使用 DockerDesktop 版本 2.3.0.3 运行 Win10,引擎在版本 19.03.8 上运行。
我正在做的是在 localhost 上公开 docker 守护程序,以便从我安装的 WSL(版本 1,而不是 2)的 Ubuntu 中使用它。
Docker 本身可以工作,我可以提取图像并做一些基本的事情。但是我在安装卷时遇到了问题:-/
当我尝试运行 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
目录 /home/myUser/myLocalDirectory确实存在。
目录 /var/lib/docker/volumes/someDir/_data在我的 WSL“主机”上不存在。只有一个 /var/lib/docker-engine/...文件夹,这显然不是我要找的那个:-/
我的工作路径是 /mnt/e/projects/myDockerProject - 但我也尝试安装/绑定(bind)文件夹/硬盘,如图所示 here .
一切都不起作用,我真的被困住了——你有什么建议/解释吗?

最佳答案

当我使用 Docker for Windows 运行 linux 容器时,我绑定(bind)挂载 c:/the/windows/path:/desired/path/in/the/container .
这里有很多层:

         ___ WSL
/
Windows
\___ Docker Linux VM -- Containers
在“正常”情况下(带有 linux 容器的 linux 主机),您绑定(bind)挂载一个本地目录。在上图中,它对应于 Docker Linux VM 中的一个目录。但是 Docker for Windows 允许我们指定一个 windows 路径。
当您将 WSL 加入其中时,事情会变得更加困惑。在 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明显对应 C:\Users ,但您无法从 df 的输出中看出或 /proc/mounts 的内容或 /etc/fstab .
我建议您尝试以下方法:
  • 指定windows路径:C:/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  • 指定以“基本”Windows 驱动器开头的 WSL 路径:/mnt/c/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  • 如果这些都不起作用,请启动 docker-compose up从 DOS 或 powershell 提示符,并使用上面 #1 中的 windows 路径
  • 关于docker - Windows Host Docker + WSL - 卷安装问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62595353/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com