简体   繁体   English

Windows WSL2 docker.exe 卷安装不同于 wsl docker 卷安装

[英]Windows WSL2 docker.exe volume mount differs from wsl docker volume mounts

I got Docker Desktop installed on Windows with WSL2 support.我在支持 WSL2 的 Windows 上安装了 Docker 桌面。 Everything works as expected.一切都按预期工作。 When I run my containers with a volume mount docker run -it --rm -v W:\projects:/projects busybox i can access all my windows files inside this folder.当我使用卷挂载docker run -it --rm -v W:\projects:/projects busybox运行容器时,我可以访问此文件夹中的所有 windows 文件。

Sadly the performance isn't that great with windows shares inside docker, so i tried to mount a path from my wsl machine.可悲的是,docker 中的 windows 共享的性能不是很好,所以我尝试从我的 wsl 机器安装路径。

i was under the impression that docker would run inside wsl?我的印象是 docker 会在 wsl 中运行? So I expected the two commands to output the same:所以我预计 output 的两个命令相同:

docker run -it --rm -v /home/:/myHome busybox ls -l /myHome
wsl docker run -it --rm -v /home/:/myHome busybox ls -l /myHome

but the output using docker is just total 0 where as the output using wsl is my home directory.但是使用docker的 output total 0 ,因为使用 wsl 的wsl是我的主目录。

Can someone explain to me where this /home directory is (physically / in wsl / my computer) when I run docker from windows?当我从 windows 运行docker时,有人可以向我解释这个/home目录在哪里(物理上 / 在 wsl / 我的计算机中)吗? And is it possible to run docker and it runs wsl docker without symlinks / path modifications so i can mount my linux directory inside the container?是否可以在没有符号链接/路径修改的情况下运行docker并运行wsl docker所以我可以在容器内挂载我的 linux 目录?

If wsl-2 is installed, you can access its file system by going to the following path:-如果安装了wsl-2 ,您可以通过以下路径访问其文件系统:-

\\wsl$

/home wouldn't just work as its not physically present in Windows's file system /home不仅可以正常工作,因为它实际上不存在于 Windows 的文件系统中

You can however use /home or any other linux based directories if you login to your wsl distro.但是,如果您登录到 wsl 发行版,则可以使用/home或任何其他基于 linux 的目录。 Please note that the following command won't mount any volumes if you run it from windows.请注意,如果您从 windows 运行以下命令,它不会挂载任何卷。 It should be run only from your wsl distro它应该只从您的 wsl 发行版运行

docker run --name mycontainer -v /home:myhome busybox

To access the /home directory in an Ubuntu-16.04 distro from windows:-要从 windows 访问Ubuntu-16.04发行版中的/home目录:-

\\wsl$\Ubuntu-16.04\home

You can replace Ubuntu-16.04 with your distro name - version您可以用您的发行版名称替换Ubuntu-16.04 distro name - version

To mount any of the directories which is under wsl, ensure that you have turned on the option "Enable integration with my default wsl distro" https://docs.docker.com/docker-for-windows/wsl/要挂载 wsl 下的任何目录,请确保您已打开选项“启用与我的默认 wsl 发行版的集成” https://docs.docker.com/docker-for-windows/wsl/

To mount a wsl 's directory from windows as a volume, provide your host volume path in the given format要将wsl的目录从 windows 挂载为卷,请以给定格式提供主机卷路径

docker run --name mycontainer -v \\wsl$\Ubuntu-16.04\home:/myHome busybox

Basically, docker run -v has an effect from which environment its being executed ie either windows or wsl基本上, docker run -v会影响其执行的环境,即 windows 或 wsl

And docker volumes are present in the following path if you have enabled wsl-2 for docker but don't want to use your distro's file system如果您为 docker 启用 wsl-2 但不想使用发行版的文件系统,则 docker 卷存在于以下路径中

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\

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

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