I switched my Docker backend from Hyper-V to WSL2

2024-03-07 | 386 words

I’ve been using Docker for nearly three years now, primarily for development purposes. As a Windows user, I’ve consistently utilized Hyper-V as the backend. This choice was mainly due to the poor performance of the WSL2 backend, particularly because I insisted on keeping my application files on the Windows partition. Although the Hyper-V backend worked adequately for me, it was still slower than production, even on my high-end desktop PC. Consequently, I never felt compelled to switch to the WSL2 backend, despite it being considered the future of Docker for some time.

Due to persistent freezing issues with my Docker Desktop, despite trying various fixes, I eventually opted to give the WSL2 backend another chance. I’m pleased to report that it’s been a game-changer. The performance is significantly improved. It’s lightning-fast! Startup times are quicker, and the application response is noticeably better.

How to switch to WSL2 backend?

It was not as painful as I thought.

I just had to change the backend in Docker Desktop settings to WSL2. Before that, I had to enable WSL2 which is easy these days.

Next, I moved my files from

C:\projects\XXXX

to

\\wsl.localhost\Debian\home\XXXX

How to access files from Windows?

Accessing files on WSL directly from Windows is very slow. It is done by accessing the network share folder \\wsl.localhost\. Using VSCode, you can connect directly to WSL2 folder and it is working perfectly.

How to run cli commands?

My preferred way is to run them directly in the WSL2 terminal (again, because of speed). I have to rewrite some of my CLI scripts from PowerShell to Bash, but it’s not a big deal.

But what about Git?

But one thing is bothering me: How to work with Git? My beloved Sublime Merge does not support connecting to WSL2. Running from Windows and accessing the repo on the Linux filesystem is extremely slow :(

One way is to install Sublime Merge in WSL and run it as a Linux graphical application. It is working pretty well, very fast, but sometimes it won’t start at all :D OMG.

Another obvious way is to use Git from the terminal, which is okay, but sometimes I need to see the changes or branches in a nice GUI.

So, I’m still looking for a better solution. If you have any, please let me know.