使用Docker桌面的WSL2上的Docker卷 [英] Docker volumes on WSL2 using Docker Desktop

查看:115
本文介绍了使用Docker桌面的WSL2上的Docker卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Windows的Docker上尝试了WSL 2,但是挂载卷出现了问题:

I'm just trying out WSL 2 with Docker for Windows and I'm having an issues with mounted volumes :

version: "3.7"

services:
    node:
        build: .
        container_name: node
        hostname: node
        volumes: 
            - ./app:/app
        stdin_open: true

容器的构建和启动良好,我可以通过docker exec很好地访问它,但是容器内的/app 文件夹未绑定到我的笔记本电脑 app 文件夹.但是,正确的路径实际上已正确安装在正在运行的容器上:

the container build and start well, I access it with docker exec nicely but the /app folder inside the container isn't bound to my laptop app folder. However the right path is actually correctly mounted on the running container :

(在这里我对主机执行pwd操作,以确保它与容器上安装的内容完全匹配)

(here I do pwd on the host to if it matches perfectly with what is mounted on the container)

➜  app pwd   
/mnt/c/Users/willi/devspace/these/app

这是搬运工的屏幕,告诉我在容器中安装了什么路径,什么都匹配.

And this is screen of portainer telling me what path are mounted where in the container and everything matches.

我在主机上的app文件夹中创建的文件在容器的app文件夹中不可见,反之亦然.这很奇怪,我不知道如何调试它.

The file I create int he app folder on the host are not visible in the app folder of the container and vice-versa. This is weird and I don't know how to debug it.

补充信息:

  • Windows 10专业版10.0.19041
  • 适用于Windows的Docker版本:2.3.0.4
  • WSL中的
  • docker版本输出:19.03.12
  • docker-compose版本:1.26.2
  • Windows 10 Pro 10.0.19041
  • Docker for Windows version : 2.3.0.4
  • docker version output in WSL : 19.03.12
  • docker-compose version : 1.26.2

谢谢

推荐答案

如@Pablo所述,最佳实践似乎正在使用WSL文件系统来映射卷.

As @Pablo mentioned, the Best-Practice seems to be using WSL File system for mapping Volumes.

看看有关WSL2的Docker文档:

  1. 要在绑定安装文件时获得最佳的文件系统性能,请执行以下操作:
    • 将源代码和其他数据绑定安装到Linux容器中(例如,使用 docker run -v< host-path>:< container-path> )存储在Linux容器中,而不是Windows文件系统.
    • 如果原始文件存储在Linux文件系统中,则Linux容器仅接收文件更改事件(初始化事件").
    • 当文件是从Linux文件系统绑定挂载而不是从Windows主机远程挂载时,性能会更高.因此,请避免 docker run -v/mnt/c/users:/users (其中从Windows挂载/mnt/c ).
    • 相反,在Linux shell中,使用诸如 docker run -v〜/my-project:/sources< my-image> 之类的命令,其中被扩展为Linux shell到 $ HOME .
  1. To get the best out of the file system performance when bind-mounting files:
    • Store source code and other data that is bind-mounted into Linux containers (i.e., with docker run -v <host-path>:<container-path>) in the Linux filesystem, rather than the Windows filesystem.
    • Linux containers only receive file change events ("inotify events") if the original files are stored in the Linux filesystem.
    • Performance is much higher when files are bind-mounted from the Linux filesystem, rather than remoted from the Windows host. Therefore avoid docker run -v /mnt/c/users:/users (where /mnt/c is mounted from Windows).
    • Instead, from a Linux shell use a command like docker run -v ~/my-project:/sources <my-image> where ~ is expanded by the Linux shell to $HOME.

这篇关于使用Docker桌面的WSL2上的Docker卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆