Upgrading to WSL 2

At the time of writing this story, WSL 2 is only available on beta and you cannot get it from regular Windows 10 builds.

To install WSL 2, you sign-up to the Microsoft Insider Program, so you can get access to their Insider Preview builds.

Once you have upgraded your current MS build to the Insider Preview build, you can start upgrading your WSL distributions to version 2.

The official MS documentation shows how to do it:

In this example, I run wsl -l to list the current WSL distributions I have.

Then I follow up with wsl --set-version Ubuntu-18.04 2 to upgrade my Ubuntu-18.04 WSL distribution to WSL 2.

Once that is complete, I can start setting up Docker for Windows.

I must mention that after about 2–3 years of continuously upgrading Docker for Windows on my machine, it started bugging out. On the latest release it would not even show the settings panel properly. So I decided to uninstall Docker for Windows and begin with a fresh install. After doing that Docker Desktop settings show up.

Note: I use Docker Desktop and Docker for Windows interchangeably. They’re the same. Older versions used to be called Docker for Windows or Mac. Docker for Windows/Mac replaced Docker Toolbox about 2–3 years ago. Docker Toolbox was Virtualbox based. Now the naming has slightly changed (again) to Docker Desktop for Windows/Mac.

This is a screenshot of the newest version of Docker Desktop for Windows, currently I’m running version on the stable channel:

Docker Desktop for Windows

The first order of business is to enable the experimental WSL 2 engine.

This is the currently available official Docker documentation on WSL 2 support: https://docs.docker.com/docker-for-windows/wsl-tech-preview/

After enabling WSL 2 I get the following notice from Docker Desktop:

As indicated by the prompt, I may need to run an administrative command via PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName $("VirtualMachinePlatform", "Microsoft-Windows-Subsystem-Linux")

Which I do:

Run command in elevated powershell:

After running that command in PowerShell, Docker Desktop automatically restarted by itself. Note that you might need to restart it yourself manually, mileage may vary.

After Docker Desktop restarts, the Docker daemon status indicator on the bottom left goes back to green and running.

From the Docker Desktop settings panel I click Resources -> WSL Integration -> Ubuntu-18.04 :

In my personal example, I have both Alpine and Ubuntu WSL distributions running in my machine. But since I only upgraded Ubuntu to WSL 2, only Ubuntu shows up.

After that I should be good to go, right? But no:

As part of my Docker Desktop + WSL 1 integration, I have the following in my ~/.profile inside WSL Ubuntu:

I comment that out:

Restart the terminal, and what do I get:

Great. No errors. I have no images at the moment because I just completely nuked Docker Desktop and re-installed the newest version, meaning I lost whatever images I had built locally. That’s OK, because it is a small price to pay for performance long-term.

Upgrading Alpine to WSL 2

There’s no point, or use case for me to have both the Docker daemon exposed via DOCKER_HOST='tcp://localhost:2375' and the WSL 2 integration.

Using Windows Terminal, I open a new shell for cmd.exe , then follow thru the motions of upgrading a WSL distribution from version 1 to version 2. First, list the current distributions:

wsl -l

Then, upgrade Alpine WSL to WSL version 2:

wsl --set-version Alpine 2

Here’s a screenshot:

No administrative permissions are needed to do this — that is, the shell does not to be running in elevated mode.

With that done, I open my Docker Desktop settings and go to Resources -> WSL Integration:

Now I can upgrade Alpine to use WSL2 integration too!

I select Alpine, then click Apply & Restart:

Now, I currently don’t use Docker within my Alpine WSL distribution, I only use Alpine to run PHP and provide intellisense to Visual Studio code. But If for some reason I needed to integrate it with Docker in the future it is ready for use.








Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Callback Insanity

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.