1

I'm using WSL on Windows while using Docker.

I am adopting this solution

https://stackoverflow.com/questions/50540721/docker-toolbox-error-response-from-daemon-invalid-mode-root-docker

So I tried to mount "mounted_folder" with "file_at_host" file here by Docker on WSL. Like...

docker run -it -v //C/Users/<username>/Desktop/mounted_folder://new_dir <image> bash 
docker run -it -v /C/Users/<username>/Desktop/mounted_folder:/new_dir <image> bash

But as you can see in the next picture, ls command shows no files.

How a folder is mounted in CONTAINER

On the other hand, I tried to do the same thing on Command Prompt.

docker run -it -v C:\Users\<username>\Desktop\mounted_folder:/new_dir <image> bash

Then I could find "file_at_host" file with ls command.

How a folder is mounted in CONTAINER

How could this happen?

And, which folder is docker referring to when it mounts folder?

Can I find that folder on Windows GUI?

Similarly, I tried to mount a folder by docker with WSL and made "something.ipynb" file in container.

docker run -p 8888:8888 -v /c/Users/<username>/Desktop/ds_python:/work --name my-lab <image>

And I couldn't find "something.ipynb" file on Windows GUI where it should be in the applicable folder "ds_python".

But, I found that "something.ipynb" file exists when I tried to mount "Desktop" by Docker with WSL.

How a folder is mounted in CONTAINER

Like the picture above,"something.ipynb" file appears, while I couldn't find it on Windows GUI "C:\Users\Desktop\ds_python".

How can I make a breakthrough about this?

"C:\Users\Desktop" and "/c/Users//Desktop/" are different?

Then how can I see the latter on Windows?

And also, how can I mount the applicable folder on Windows with WSL by Docker?

3

2 Answers 2

1

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
5
  • Thank you for your cooperation. So to speak, Linux(WSL2) mount Windows as /mnt, right? Then how can I find the applicable folder when I type "/c/Users/<username>/Desktop/<folder>" ??? Now I understood I should type "/mnt/c/Users/<username>/Desktop/<folder>" when I want to mount <folder> by Docker. But I can't find any clue about how to check the former pattern not the latter. Commented Dec 13, 2021 at 1:27
  • @user-polymetis I have updated my answer. You need to use the full path, including /mnt
    – Sathyajith Bhat
    Commented Dec 15, 2021 at 11:11
  • Thank you for your kindness. Now I can also know access authorization as well thanks to you. Thank you very much!! Can I reference "/c/Users/<username>/Desktop/<folder>" on Windows GUI??? Not "/mnt/c/Users/<username>/Desktop/<folder>" with WSL. May I have any clue??? Commented Dec 16, 2021 at 4:57
  • Not sure by what you mean by Windows UI - if its Windows explorer, `c:\users` etc us available. Not in the format you mention
    – Sathyajith Bhat
    Commented Dec 17, 2021 at 20:47
  • It's all settled!! thanks!! Commented Dec 18, 2021 at 1:56
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .