Confused by how to apply 'best practices' for wsl2 and file performance


I’ve been using the HyperV backend on Docker Desktop for a while now because I saw better performance than from wsl2 when I tested running and debugging a Laravel app using it.

I found that acceptable until I moved Laravel to use Vite to build and develop. Vite take can 3 minutes to start inside my containers, so I figured it was time to try working using docker ‘best practices’ to see if that sped things up.

As I understand it, best practice is to keep your source code inside Linux, and not on the host (Windows) OS (where mine currently resides). And make those Linux code files available to your containers.

So I’ve moved my code inside ~/source/ on my default Ubuntu20.04 wsl2 distro. As I think that’s the best place to keep it.

My issue is what’s the best way to make that code available to my docker containers?

Currently in my docker compose file (that I run from Windows) I have a volume defined like this:

 - '\\wsl.localhost\Ubuntu-20.04\home\wsl_root\source\:/var/www/'

Is this best practice or not?
Will I get the best file system performance doing this? OR should I be changing my working methods to actually run docker compose from within my default linux Distro? Not from windows? And mounting the volume like this?

 - ~/source:/var/www/'

I’ve read the docs and this doesn’t entirely make sense.


You can optimize your workflow depending on your IDE.

For instance if you use VSCode, you can use the WSL extension, which starts a backend service inside the WSL distro, sets the working scope to the WSL2 distribution and only uses VSCode on the Host to render the output.

If you work with IntelliJ, I find it preferable to directly work inside WSL2. Thanks to WSLg the Desktop will be rendered on the Windows host via an automatically established RDP connection. WSLg was backported to Win10 and is available in recent WSL versions (use wsl --update to use the latest version).

Both allows you to work, as if you work on a Linux machine. You can start a terminal inside your IDE and execute commands in your WSL2 distribution directly. If you enable WSL-integration in Docker Desktop for this distribution, you can use all docker commands from inside the distribution. So yes, the recommendation is to use docker compose inside the WSL2 distribution.