简体   繁体   中英

Windows WSL2 docker.exe volume mount differs from wsl docker volume mounts

I got Docker Desktop installed on Windows with WSL2 support. 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.

Sadly the performance isn't that great with windows shares inside docker, so i tried to mount a path from my wsl machine.

i was under the impression that docker would run inside wsl? So I expected the two commands to output the same:

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.

Can someone explain to me where this /home directory is (physically / in wsl / my computer) when I run docker from windows? 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?

If wsl-2 is installed, you can access its file system by going to the following path:-

\\wsl$

/home wouldn't just work as its not physically present in Windows's file system

You can however use /home or any other linux based directories if you login to your wsl distro. Please note that the following command won't mount any volumes if you run it from windows. It should be run only from your wsl distro

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

To access the /home directory in an Ubuntu-16.04 distro from windows:-

\\wsl$\Ubuntu-16.04\home

You can replace Ubuntu-16.04 with your 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/

To mount a wsl 's directory from windows as a volume, provide your host volume path in the given format

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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