Docker on Hyper-V vs WSL 2

I'm using Docker Toolbox, recently I got to know about the Docker installation using WSL 2.

What are the differences between Hyper-V and WSL 2? Which has better performance?


Please read this: https://www.docker.com/blog/docker-hearts-wsl-2/

We will replace the Hyper-V VM we currently use by a WSL 2 integration package. This package will provide the same features as the current Docker Desktop VM: Kubernetes 1-click setup, automatic updates, transparent HTTP proxy configuration, access to the daemon from Windows, transparent bind mounts of Windows files, and more.

A technical preview of Docker Desktop for WSL 2 will be available for download in July. It will run side by side with the current version of Docker Desktop, so you can continue to work safely on your existing projects. If you are running the latest Windows Insider build, you will be able to experience this first hand. In the coming months, we will add more features until the WSL 2 architecture is used in Docker Desktop for everyone running a compatible version of Windows.

Additionally I recommend to watch this video: https://www.youtube.com/watch?v=lwhMThePdIo

Good comparison you will find here: https://blog.logrocket.com/working-with-node-js-on-hyper-v-and-wsl2/

cite:

Comparing Hyper-V to WSL2

The biggest difference between running Ubuntu Linux in a Hyper-V virtual machine versus running the operating system in WSL2 lies in the ability to access the Ubuntu user interface in Hyper-V.

The user interface allows you to install and use more than just command-line tools.

Depending on your system’s hardware performance, you likely found that WSL2 is the faster option. To expedite the process of running Ubuntu Linux on Hyper-V, you could set up SSH access to the virtual machine.

This speeds up command-line access. However, WSL2 may still have the upper hand since it does not require SSH to enable access.


Hyper-V and WSL2 (WSL2 runs on Virtual Machine Platform, the name of Hyper-V's architecture packaged separately and made available to all SKUs) could have negative interactions with other VM solutions, for example VirtualBox v5 and under will not coexist with Hyper-V. As of VirtualBox v6+ there is support to run VirtualBox in a configuration to replace its own virtualization with that of Hyper-V paravirtualization. In the recent past there are reports that 'performance will be worse' as outlined in Use VirtualBox and Hyper-V simultaneously. If this is of particular interest to you, I'd encourage you to research what progress has been made on that front.

When people judge WSL2 as being "faster" they're typically talking about setup time being easier and thus faster. Actual performance depends on how many presets and customizations were made for WSL2's Hyper-V instance but more importantly, it depends on your use cases.

  • Will you ONLY use WSL2 for Docker?
  • If no, how do you plan to use WSL2 outside of Docker?
  • Do you currently or plan to use any other Virtual Machines?
  • Do you require a lot of direct Win 10 <-> WSL2 file access (WSL2 has poor file system performance when lots of file activity takes place between the two)?

In the most basic of answers:

If you're ONLY using docker:
WSL2

If you require Linux, additional VMs or want access to Docker's Advanced tab for resource allocation:
Hyper-V

Final Note:
Although Hyper-V is officially unsupported for Windows 10 Home edition and is stated so throughout published material, there is a proposed way to enable it which can be found in this MicrosoftDocs Virtualization-Documentation issue posting. While I am unable to comment on how well it works or if it works at all, there are guides available if you wish to try.