HELLO Docker Desktop Windows Subsytem for Linux 2 Tech Preview
Tags: ubuntu, docker, tutorial
Published: 2019-11-09 18:50:54

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`.](https://docs.docker.com/docker-for-windows/wsl-tech-preview/)

### [Why is this amazing?](#why)

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?](#prerequisites)

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?](#install)

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.](https://insider.windows.com/en-us/)
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](#enable)

In **PowerShell as Administrator** run the following commands:
```powershell
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 <Distro> with the distro you're using.
```powershell
wsl --set-version Ubuntu  2
wsl --set-default-version 2
```

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

```powershell
wsl -l
```

**Now we got all the POWER Linux kernel**
![Fire](https://i.kym-cdn.com/entries/icons/original/000/022/134/elmo.jpg)

##### 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](#upgrade)
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.

```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.

```bash
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: 
{% github https://github.com/yarnpkg/yarn/issues/4453#issuecomment-329463752 %}

### [Installing Docker Desktop WSL 2](#installing_docker)
[You can download the special build of Docker Desktop here](https://docs.docker.com/docker-for-windows/wsl-tech-preview/#download)

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](https://docs.docker.com/docker-for-windows/images/wsl2-ui.png)

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

### [Running Docker in WSL2](#running)
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:
```bash
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](https://i.imgur.com/35hRzgm.jpg)

Go and have fun!