Increase Docker speed on Windows by setting up Windows Subsystem for Linux 2
Tl;dr Increase Docker speed when developing on Linux containers in Windows by installing a preview version of Windows, installing WSL 2 and by using the Edge version of Docker.
Published:
When working with Docker, even in a Windows development environment, the default option is to use Linux containers. Microsoft have made it possible to run Linux containers in Windows through what is called Windows Subsystem for Linux (WSL), which is a layer between Windows and Linux distros like Ubuntu.
All calls to from Windows to the Docker container are translated on the way, and especially operations that read and write to disk have been quite slow. This causes a significant overhead compared to running Linux containers on a Linux machine.
Earlier this year Microsoft released version 2 of WSL, which was a major rewrite of the WSL architecture. WSL 2 works by running a custom Linux kernel inside Windows. This kernel has direct access to Windows' file system, which means the file handling is a lot faster in WSL 2 compared to WSL.
Read more about the release of WSL 2 on Microsoft's developer blog:
https://devblogs.microsoft.com/commandline/announcing-wsl-2/
The Docker developers have since released a preview (Edge) version of their Windows application, to take advantage of WSL 2.
As a developer working in Windows, there are 3 steps you need to take to use the faster Docker version:
Install Windows 10 Preview
Install WSL 2
Install Docker Edge
Install Windows 10 preview
To install preview versions of Windows, you need to join the insider program:
Open Settings from the start menu
Open Update & Security
Open Windows Insider Program
Follow the wizard to join the insider program, you need to have a personal Microsoft account to join. To be able to install WSL 2, you only need the "Slow" setting, meaning you will get a pretty stable preview version of Windows.
After you have joined the insider program, go to Windows Update to install the next preview version of Windows.
This takes a while, go grab a coffee while you wait.
Install WSL 2
In a command window, run the following command to see what version of WSL you have:
C:\> wsl --list --verbose
If you don't get anything here, you probably don't have WSL installed or enabled at all.
Follow this guide to set up WSL:
https://docs.microsoft.com/en-us/windows/wsl/install-win10
If you get a list with one or more Linux distros, like Ubuntu, and version 1, follow this guide to enable WSL version 2 and update your distro to take advantage of it:
https://docs.microsoft.com/en-us/windows/wsl/wsl2-install
When you run the command again, you should see something like this:
C:\> wsl -l -v
NAME STATE VERSION
Ubuntu Stopped 2
Install Docker Edge
Install Docker Desktop for Windows
Run it
Right click the Docker icon on the taskbar and select Settings
On the settings page in Docker, you should have a link at the bottom, like this:
Click the link to switch to another version.
Select "Docker Desktop Edge" and install it.
NB! If the installation of Edge through Docker doesn't work (it didn't for me), download Docker Edge directly and run the installer.
The easiest place to find the newest Edge release at the moment, is through the Docker Edge release notes here:
https://docs.docker.com/docker-for-windows/edge-release-notes/
If you run into any problems, have a look at the Docker documentation for enabling WSL 2:
https://docs.docker.com/docker-for-windows/wsl-tech-preview/
Enable WSL 2 support in Docker Edge
Open the Docker settings, by right-clicking the Docker icon on the taskbar.
Enable WSL 2:
If you got this far, good job!
Lean back and enjoy faster startup times and faster file reading and writing when running your Docker Linux containers in Windows.
Categories: Docker