DEV Community

Erik Guzman
Erik Guzman

Posted on

HELLO Docker Desktop Windows Subsytem for Linux 2 Tech Preview

A couple of days ago, during my Thursday Twitch stream. I made the amazing discovery that Docker has a Docker Desktop WSL 2 Tech Preview.

Why is this amazing?

Now applications that are running inside of Linux Subsystem can directly run docker!! You don't have to do any work around forcing you to keep the project on the Windows kernel because Docker Desktop couldn't handle file path pointing inside of the Linux Subsystem (like I had to do). It also comes with added performance:

Docker Desktop also leverages the dynamic memory allocation feature in WSL 2 to greatly improve the resource consumption. This means, Docker Desktop only uses the required amount of CPU and memory resources, enabling CPU and memory-intensive tasks such as building a container to run much faster.

Also, in general, it's amazing to do web development in the Linux Subsystem since you will encounter libraries, packages, and instructions only for Linux.

Ok already, just what do I need to do to use it?

There are a couple of prerequisites you need in order to take advantage of new Docker goodness:

1) Install Windows 10 Insider Preview build 18932 or later.

2) Enable WSL 2 feature on Windows. For detailed instructions, refer to the Microsoft documentation.

3) Install a default distribution based on Ubuntu 18.04. You can check this with wsl lsb_release -a. You can download Ubuntu 18.04 from the Microsoft store.

How do I install WSL?

WSL 2 is only available in Windows 10 builds 18917 or higher. So that means you will need to opt-into the Windows Insider Program to get beta builds of Windows, so be aware of this fact.

Join the Windows Insider Program and select the 'Fast' ring.
You can check your Windows version by opening Command Prompt and running the ver command.

Now you need to install a WSL Distro, Windows has a great and simple guide for this part of things. For docker, you will need to install Ubuntu: https://docs.microsoft.com/en-us/windows/wsl/install-win10

Enabling WSL2 Distro

In PowerShell as Administrator run the following commands:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Now we want to tell WSL to use our distro of choice in WSL2. Replacing with the distro you're using.

wsl --set-version Ubuntu  2
wsl --set-default-version 2

Not sure what distro you're on? Use this command to check.

wsl -l

Now we got all the POWER Linux kernel
Fire

Pro Tip

Add all working projects directly into the Linux Subsystem instead of running files living on the Windows system. There is a major performance boost since the Linux Subsystem doesn't have to go and communicate over the virtual network to the files sitting on the Windows side.

I already have WSL2 installed on my machine

Nice, but you need to make sure you are running Ubuntu 18.04. In my situation, I was running Ubuntu but did not have the latest version. If you don't know which version you're on you can check using the following command in PowerShell.

wsl lsb_release -a

If you need to upgrade to Ubuntu 18.04 you can do so running these commands as I did inside of WSL Ubuntu.

sudo apt dist-upgrade
sudo apt update
sudo do-release-upgrade

If you come across a yarnpkg error while trying to run the updates I found the solution to the issue here:

Comment for #4453

viktorku avatar
viktorku commented on

Doing curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - again was enough.

Installing Docker Desktop WSL 2

You can download the special build of Docker Desktop here

After installing you might need to update your system to get things working with WSL2

Do not update the version. For me when I did the WSL2 Tech Preview option was gone

After its installed you can enable WSL2 integration by going to the dock menu and clicking the button shown here.
Docker menu

It should open up a dialog where you can just click start and begin the fun.

Running Docker in WSL2

Now running Docker in any of your projects inside of Ubuntu is no different from running it in PowerShell. But now with all the power and knowledge that Docker is running in a different system. So clone your projects or copy them over into the Linux Subsystem and run:

docker
# or
docker-compose up # in my case

Now you're suited up and ready for battling projects in WSL2 using docker
Ready for Battle

Go and have fun!

Top comments (0)