Hello, I am trying to use Docker Desktop for Windows 11. It made WSL environment called docker-desktop, where I created some file index.html within /home/web folder. Then I created in C:\docker file docker-compose.yaml and mount volume /home/web:/var/www/html (for Apache for example).
Problem is that left side of mounting Docker trying to find in Windows C-disk, not within WSL, where Docker run. Is possible to force mounting to WSL?
Yes, I can mount files from Windows using this syntax with absolute path //c/some/path, but having Laravel application with thousand files is this kind of mounting rejected (because it’s very slow).
What I need? Different distro? And how to mount folders through distros? I missed something important when reading docs…
You create the files inside the docker-desktop distribution?
The docker client needs to be able to access the host path in order to bind it into a container path. That’s probably the reason the windows docker client tries to find the path on the Windows host.
Generally, mounting Windows folders into container paths is done by leveraging the 9p protocol, which comes with a performance penalty, especially if many small files are involved.
That’s why people either use named volumes to persist data, or use a distribution (like Ubuntu), enable the WSL Integration for this distro in the Docker Desktop settings, and run the commands inside the distro.
Thank you for your reply @meyay!
Can you send me some link that covers named volumes to persist data for this usecase?
And am I correct, if I write, that installing WSL Ubuntu and the only one change in Docker Desktop settings replaces scope from Windows path to Ubuntu path for all docker-compose files? Or there are other steps to do?
With named volumes, you first declare the volume in the volume top level section, so that it can be used in the service. Those are listed by the command docker volume ls
There are also anonymous volumes, created if a Dockerfile has a VOLUME instruction for a specific container path, and the container was created without mapping a named volume, or binding a hostpath into the container path. Anonymous volumes are listed by docker volume ls and have a random alphanumerical name.
Host paths are not really volumes, as they bind a host folder into a container folder. Binds are not listed by docker volume ls
It doesn’t change anything for the docker cli in windows. Though, if the WSL integration is enabled for Ubuntu, and you store your data in the Ubuntu distribution and run your docker compose commands inside the distribution, it will use the paths inside the wsl distribution. In this scenario, binding host paths will just work, like it does with docker-ce on any other Linux distribution.