Let's say you're on Windows and you want to mount a volume like so:
docker run --name nginx -v "C:\\my\\path:/usr/share/nginx/html" -p "8080:80" nginx
This works perfectly with Docker Desktop, which uses WSL2.
However, with a custom Docker in WSL2, you'll get:
docker: Error response from daemon: invalid mode: /usr/share/nginx/html.
There are some questions covering this topic:
- Docker on Windows without Docker Desktop volume mounting
- Docker Desktop for Windows, having trouble w/ -v bind mount
- How do you create a bind mount in Docker when running with the WSL2 backend?
Their bottom line is: Use /mnt/c/.... But Docker Desktop doesn't need this. When you inspect a container created by Docker Desktop, you'll even see:
"Mounts": [
{
"Type": "bind",
"Source": "C:\\my\\path",
"Destination": "/usr/share/nginx/html",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
How is it possible that Docker Desktop's WLS2 Docker daemon can handle Windows paths?