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.
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.
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.
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.
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
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.
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.
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:
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
It should open up a dialog where you can just click
start and begin the fun.
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
Go and have fun!