When I try mounting a bind volume using the command docker run --rm -it --mount type=bind,source=/c/Users/My_username/docker/test/src/,target=/data alpine sh Running ls -la /data in the container results in the following:
/ # ls -la /data total 0 drwxr-xr-x 2 root root 40 Aug 22 10:40 . drwxr-xr-x 3 root root 60 Aug 22 10:40 ..
No files are present within the container, even though there is a file in the folder on the host machine:
PS C:\Users\My_username\docker\test> ls c:/Users/My_username/docker/test/src/ Directory: C:\Users\My_username\docker\test\src Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 22/08/2018 21:25 50 index.php
I expected index.php to be inside the /data folder on the container. Using any other way of writing the source path (e.g. C:/Users, c:/Users, c/Users) results in an error. My C drive is set to be shared in the settings under Shared Drives. I am using docker version 18.06.0-ce, build 0ffa825 on Windows 10.
How can I make sure the files in the source folder get copied over to the container?
I am also having this issue, for quite some time now. Same story: I’m sharing my C drive and have tried both COPY and ADD to add files, also defined volumes in various ways. All my docker stuff works fine in macOS on other computers but I need it to work in Windows with Docker running in Windows and my code running in the Windows Linux Subsystem.
Is anyone looking at this? It’s been pretty hard even to find this post (posting this reply in hopes it becomes more visible and someone somewhere answers my and OP’s question).
By default, WSL mounts drive C: as /mnt/c, but Docker expects paths that start with /c. To be able to mount volumes from WSL command line you have to change the mount point by adding the following to /etc/wsl.conf: