Mounting path on wsl2

I am running Docker-Desktop with wsl2 backend. I am trying to mount a path in onto my container and edit files from the container and have that reflect onto my host filesystem. In the Docker UI the path is shown as mounted but its not mounting the files that are on my host’s filesystem

What i do is:
docker run --rm -d -v /home/my_user:/home/my_user ubuntu

in my host systems /home/my_user i have a directory called foo. It not not visible inside the docker container and also changing files does not reflect on my host system.

Now i check my host fs with:
wsl -u my_user -> cd /home/my_user
no changes to be seen.

Am i missing something?

I wonder what you mean by host fs. Why would the Windows host use linux file paths?

I thought wsl2 basically lets me run docker through a linux distro. I was under the assumption it would use linux file paths because it allows me to use the /home/my_user path with does not exist on my windows machine. Where is the mount point then?

The file system of a WSL does not share anything with the host’s filesystem. Your folder/home/my_user is not shared with the host, it only lives in the WSL distros filesystem. Windows drives are mounted into the wsl distro underneath the /mnt folder.

If you run the docker command inside a WSL distribution, you can use this command to determine your windows userprofile path: wslpath $(powershell.exe -c 'Write-Host -NoNewline ${env:USERPROFILE}').

Assumed the Windows path is C:\Users\meyay, the command will print the output /mnt/c/Users/meyay

Though, if you run your docker commands in a terminal on the host, you can directly use the Windows path.

Please be aware that file access will be much slower, if a container access folders from the host filesystem. A paid Docker Desktop subscription gives you access to synchronized file sharing, which should be much faster.

okay but i am confused about what happens then if i run -v /home/my_user:/home/my_user` from my windows terminal. The path is neither in my linux distro neither on my windows and i cant see it on docker as a volume, so where can i find it?

Great question! As it was never intended to be used like that, I never tried (and don’t feel like trying), I can only assume that it uses a path inside the docker-desktop-data distribution.

You can check by opening this UNC in the file explorer: \\WSL$\docker-desktop-data

Update: now I tried, and my assumption was wrong. I have no idea in which black hole the host side disappears. After all, It was never meant to be used like that.

When you say “host filesystem”, you mean the WSL distribution or the Windows filesystem? Do you expect to see files in your container that were in your default WSL distribution’s home or in your user’s home on your Windows host?

If WSL integration is enabled, you can indeed mount files from the WSL distribution into the containers in Docker Desktop. So if you run the docker command in your WSL distribution for which WSL integration is enabled in Docker Desktop, you should be able to use the docker command almost as if Docker was installed in that distribution. I emphesize “almost” since the daemon is still running in another distribution so container IP addresses will not be available directly.

I don’t understand this. You mean the content is not visible or the folder itself is not visible?

If files are not mounted properly, that can be a Docker Desktop bug or there is something special in that folder we can’t even think of.