Searched the internet and Stackoverflow for this but had no success
Using Docker for Desktop version 4.12.0 on Windows 10 with WSL2 as the backend.
In the Windows command prompt window, the following works and lists files in c:/data
docker run --rm -v c:/data:/target alpine ls /target
But none of the following works. /target directory is always empty!
docker run --rm -v d:/data:/target alpine ls /target
docker run --rm -v "d:/data:/target" alpine ls /target
docker run --rm -v "d:/data":/target alpine ls /target
docker run --rm -v /mnt/d/data:/target alpine ls /target
docker run --rm -v /run/desktop/host/d/data:/target alpine ls /target
docker run --rm -v "/run/desktop/host/d/data:/target" alpine ls /target
However, within the WSL 2 terminal window following works and lists files under /target directory!
docker run --rm -v /mnt/d/data:/target alpine ls /target
But I want to use Docker Desktop for Windows and use the Windows command prompt. Ultimately, I want to mount volume inside docker-compose.yml.
Some of the above commands seem to have been working for different people based on StackOverflow answers in past. Don't know if it's because of a different version of Docker for Desktop or not clear if they were trying in the WSL2 terminal window or Windows command prompt window.
You are facing a Microsoft limitation regarding Docker volumes:
"We support mapping a whole second drive letter, but for now, not portions of it. "
You have to just mount the complete d drive, as d:
Other options such as root (d:\), or paths (d:\somefolder) won't work with the second drive.
In your case, that means doing something like:
docker run -it -v d: alpine ls /d/data
If that creates an empty d folder inside your container, that means you're hitting permission issues within the drive.
Note that even if the issue comment is from 2016, seems like the limitation is still kicking in...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With