How to access / mount Windows filesystem in WSL 2 mode?

docker Windows v.19.03.13 / Windows 10 Pro v2004 (19041.508) clean install of both from scratch.

Everything seems to work fine, but I can’t figure out how to access the Windows file system. There is no file sharing tab in Docker Desktop Settings, as expected because WSL 2 is checked.

The documentation [https://docs.docker.com/docker-for-windows/] says that “…in WSL 2 mode and Windows container mode all files are automatically shared by Windows”.

I cannot find any examples in the documentation.

If I run a ubuntu container, the /mnt and /media directories are empty, and nothing relevant is shown by ‘mount’ as far as I can tell.

I’ve tried variations of -v and --mount with no success, typically I get errors like “Error response from daemon: invalid mount config for type “bin.source=e:” mount type unknown”.

Can someone provide or link to examples that show how to bind-mount, or otherwise access, Windows files from a container, showing how to deal with Windows specific issues such as drive letters and backslashes?

The easiest is like this:

PS C:\Users\xy> docker container run --rm -it -v "$(pwd):/data" debian bash

Mounts the current folder into /data in a Debian container and opens a bash shell.

1 Like

I am sorry, I do not get what I should with it. What is xy? What is pwd? Could you please provide more details?

PS C:\Users\xy> is just the powershell prompt where xy is the username. The rest of it is the command you can run to test the mount. pwd is a command on Linux to get the current working directory on the host. On Windows it is an alias to “Get-Location”. Source: Windows PowerShell equivalent to Unix/Linux `pwd`? - Super User

Thank you! After I run this command I simply get into my container from terminal. How can I access the Windows file from it? Or, alternatively, how can I access the files in this container from Windows?

Read the documentation of docker run to understand the parameters: Docker run reference | Docker Documentation

Your host filesystem is mounted to /data inside the container.

You can’t access the container filesystem directly from Windows

Thank you, I see now!