Windows Subsystem for Linux (WSL) 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation. With Docker Desktop running on WSL 2, users can leverage Linux workspaces and avoid having to maintain both Linux and Windows build scripts. In addition, WSL 2 provides improvements to file system sharing, boot time, and allows access to some cool new features for Docker Desktop users.
Docker Desktop uses 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 it needs, while enabling CPU and memory-intensive tasks such as building a container to run much faster.
Microsoft first announced Windows Subsystem for Linux 2/WSL 2 during Microsoft Build last year and it was rolled out to the stable version earlier this year with the Windows 10 May 2020 update (version 2004). The update introduced a full Linux kernel to the stable Windows 10 branch and the company also made WSL 2 updatable through Windows Update, which meant that users no longer had to rely on the command line option to update the kernel. Now, Microsoft is bringing WSL 2 support to older versions of Windows 10.
This means that these developers will be able to take advantage of WSL 2 and Docker’s integration, allowing developers to store their code within their WSL 2 distro and run the Docker CLI from within this distro. This removes the need to access files stored on the Windows host and provides significant performance improvements for users.
According to a recent post on the Windows Command Line blog, WSL 2 support is making its way to Windows 10 version 1903 and 1909 via an update. However, the backport will only be available for x64 systems, and users who are running an ARM64 version will need to update to Windows 10 version 2004 to gain access to WSL 2.
Install August 2020 Cumulative Update for Windows 10 v1903
In case you’re one of the many users running Windows 10 version 1903 or 1909, you can head over to the Update & Security section in the Windows Settings and click on Check for Updates to see if you’ve received the update. As the blog post explains, you can check if you’ve received the backport by verifying the minor build number of your current Windows 10 build. Or even you can force to install the latest cumulative update by manually download. Get the KB4566116 here.
Install Windows Features
After we have the correct build number, let’s install first ‘Windows Subsystem for Linux’ and then prerequisites for Docker:
Enable-WindowsOptionalFeature -FeatureName Containers-DisposableClientVM -Online Enable-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online Enable-WindowsOptionalFeature -FeatureName Microsoft-Windows-Subsystem-Linux -Online Enable-WindowsOptionalFeature -FeatureName VirtualMachinePlatform -Online Restart-Computer -Force
Set WSL 2 as your default version
You might see this message after running that command: WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel
Please follow the link and install the MSI from that page on our documentation to install a Linux kernel on your machine for WSL 2 to use. Once you have the kernel installed, please run the command again and it should complete successfully without showing the message.
Install Docker Desktop
Download and install Docker Desktop on Windows from this site.
Now you can run a Linux container using Docker Desktop for Windows, running on Windows 10 v1903 (!) using the Windows Subsystem for Linux 2 (WSL 2).
Happy development with Docker and WSL2!