WSL2 && Docker && VirtualBox

WSL2 && Docker && VirtualBox

Before WSL2, Docker && VirtualBox in Windows (where else?) will always return false as Docker uses Hyper-V (Type 1 hypervisor) which when turned on, disables VirtualBox (which is a Type 2 hypervisor). So it's literally that you cannot have the best of both worlds except that it may be possible if you use Docker Toolbox instead except that I never really managed to get it working properly on my machine to the extent that I gave up (well, resistance is futile). TBH, this set back my learning and work with Docker to the Stone Age.

However, when I was watching a Microsoft Build video today on Windows Terminal and WSL2, I came to know that WSL (Window Subsystem for Linux) version 2 is now available and that it has full support for Docker! That sort of made me sat up on my sofa and after patiently finishing that video, I wanted to go try it out as there was no Docker support in WSL version 1 and it really means that now I can finally have both Docker and VirtualBox to co-exist on my Windows machine and yes, they sure did!

WSL2

To install WSL2, I had to upgrade my windows build to 2004 which was simply a matter of joining the Windows Insider Program and selecting the "Release Preview" option. It did take a while for the updates to be completed. Installing WSL2 itself is very smooth, no hiccups.

No alt text provided for this image

I am using Ubuntu as my default distro and the above screenshot was that of Windows Terminal (you should check it out if you want to have a decorated command prompt).

Now the icing on WSL2 is if we use VSCode with its Remote-WSL extension, we can have a native local Linux development environment that is 1. fast and 2. have access to your local filesystem. No more laggy SSH or SCP or Remote-SSH with VSCode. In fact, this is a big win for Windows-based developers who need to use some linux tools (I can see now the I-told-you-so grins wiping off the macbook fanboys. Sorry folks, WSL2 got this one).

No alt text provided for this image

Docker

Installing Docker was also straightforward. Just need to install the latest stable version of Docker Desktop and check the option to integrate WSL2.

No alt text provided for this image

Installing the Docker Desktop in this way does not turn on your Hyper-V.

No alt text provided for this image

Install the Remote-WSL extension in your VSCode and that's it, we are all set.

Start the Docker Desktop first (if it has not been set to automatically launched from boot). In your Command Prompt or Windows Terminal, go to your project folder and then do a

wsl code .

This will start a VSCode Remote-WSL session. From then on, you can perform the usual docker operations, all within your Windows computer. Voila!

No alt text provided for this image

Hope this article is useful to you. Thanks for reading and I will see you soon in the next article.

another use case for WSL2 => ruby on rails! Setup more straightforward than windows

Like
Reply

To view or add a comment, sign in

More articles by William Ku

Others also viewed

Explore content categories