Docker on WSL. Want to mount a applicable folder on Windows10 with WSL

If you're using WSL2, the Windows drives are exposed on the /mnt endpoint

 ls -lah /mnt
total 12K
drwxr-xr-x 10 root   root   4.0K Nov 13 13:13 .
drwxr-xr-x 17 root   root   4.0K Dec 12 11:12 ..
drwxrwxrwx  1 sathya sathya  512 Dec  6 12:47 c
drwxrwxrwx  1 sathya sathya 4.0K Dec  2 10:31 d
drwxrwxrwx  1 sathya sathya 4.0K Dec  2 10:31 e
drwxrwxrwx  1 sathya sathya 4.0K Dec  2 10:31 f
drwxrwxrwx  1 sathya sathya  512 Dec  2 10:31 g
drwxrwxrwx  1 sathya sathya 4.0K Dec  2 10:31 h
drwxrwxrwx  2 root   root   4.0K Nov 13 13:13 i
drwxrwxrwt  2 root   root     40 Dec 12 11:12 wsl


to mount your Windows files, you would use the same format as mentioned above, ie provide the full path, including the leading /mnt as a bind mount,

docker run -it -v /mnt/c:/host/c alpine sh

With this, your C drive is mounted to /host/c in the container.

ls -lah /host/c

drwxrwxrwx    1 1000     1001         512 Dec 15 07:42 .
drwxr-xr-x    3 root     root        4.0K Dec 15 10:35 ..
lrwxrwxrwx    1 1000     1001          12 Sep 29  2018 Documents and Settings -> /mnt/c/Users
dr-xr-xr-x    1 1000     1001         512 Dec  9 16:54 Program Files
dr-xr-xr-x    1 1000     1001         512 Nov 13 11:03 Program Files (x86)
drwxrwxrwx    1 1000     1001         512 Nov  7 13:26 ProgramData
dr-xr-xr-x    1 1000     1001         512 Oct  2 08:39 Users
dr-xr-xr-x    1 1000     1001         512 Dec 15 07:43 Windows

First, the solution of Stack Overflow I adopted when I specified the mounted folder is old information and it's about Docker Toolbox not for WSL.

So, I found out it was not applicable to my situation.

Second, I should specify the mounted folder on WSL like...

docker run -it -v /mnt/c/Users/'username'/desktop/mounted_folder:/new_dir <image> bash

Third, if I specify the mounted folder like,

/c/Users/'username'/desktop/mounted_folder

I can check the folder on GUI by the path like,

\\wsl$\Ubuntu\c\Users\'username'\desktop\mounted_folder

explorer result image

I should type \\wsl$\Ubuntu~, because the distribution of WSL was Ubuntu. Ubuntu-20.04 is installed though.

Result of wsl --list -v

screenshot of wsl --list -v result

If I specify the mounted folder like,

/mnt/c/Users/'username'/desktop/mounted_folder

I can check the folder on GUI by the path like,

C:\Users\'username'\Desktop\mounted_folder

If you want to check the mounted folder on the command line on Windows in the former case, you should use PowerShell. Not Command Prompt.

Command Prompt Error