Switch to Docker with Windows Subsystem for Linux enabled

See how easy and painless one can switch from Hyper-V virtualization to WSL virtualization with Docker Desktop. Despite the process being painless, be warned that all your images are gone and need to be recreated.

Switch to Docker with Windows Subsystem for Linux enabled

Since several years we are using Docker Desktop (Docker for Windows) for our daily development work. As time goes by, updates after updates have been installed, most of them went very well, but a few brought bigger problems to the desk. Especially the update to version 2.5.1 crashed completely. A downgrade to version 2.5 seemed to be a quick fix, but since then, Docker did not seem to run as smooth as before, getting in the way of the development workflow again and again.

This seemed to be the right time to add another 1TB SSD to our laptops and re-install Docker from scratch. So here we go...

Uninstall Docker

The uninstall process is documented in detail not only for Windows 10 but also Windows Server 2016 in the uninstall guide of Microsoft. Here's the short version for Windows 10 and keep in mind - we're doing a reinstall and want to keep working with Docker and Windows based images, so we're keeping a few things like Hyper-V. And, we're not using Docker Swarm at all:

Step 1: Cleanup

# Stop all running containers
docker ps --quiet | ForEach-Object {docker stop $_}

# Remove all containers
docker system prune --volumes --all

Step 2: Go to Add or remove Programs and  uninstall Docker for Windows.
Step 3: Reboot :)

Starting from Scratch

To get back to business, use the installer provided by Docker itself. Note that since v3 of Docker Desktop, the Edge and Stable channel are merged into one single release stream. Also make sure to leverage the better performance for Linux containers by using WSL2 (you need at least Windows 10 2004).

Move Docker WSL Image to Second SSD

As usual Docker installed its WSL VM in %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx. Having a second SSD, we'd rather prefer to move the image to that second drive.

Luckily reconfiguring this is quite simple. Just follow these steps:

Stop Docker Desktop if it's running, then execute the following on an admin PowerShell console:

wsl --list -v

This gives you a list of all existing WSL VM's on your system.

  NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

Continue by exporting, de-registering and importing your docker data back  into WSL:

wsl --export docker-desktop-data "<your-location>\docker-desktop-data.tar"
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data "<path-of-new-home>" "<your-location>\docker-desktop-data.tar" --version 2

Note: the --version 2 switch at the end of the import forces WSL to use WSL2. This is not required if you're already running v2 (as we are - you can see it in the  3rd column in the list of available images).  You might also simply set v2 as the default with wsl --set-default-version 2.

So, is that it? - you're asking. Absolutely! Since we're using WSL2 for our container, we can run Docker without Hyper-V and the older data-root configuration is not needed anymore as long as we're only using Linux based containers. But of course we're not!

Move Docker Data Folder to Second SSD

Of course we're using Windows containers for Sitecore, aren't we? So, let's switch Docker to Windows containers and either go to Settings... > Docker Engine in the Docker UI and add "data-root": "d:\\you-path\\docker" or directly edit the now existing C:\ProgramData\Docker\config\deamon.json file and add the data-root there.

Potential Issue after a Re-Installation

We've seen Alpine distribution errors like "WSL integration with distro Alpine unexpectedly stopped with exit code 1". This may happen if you installed a new Alpine distro which is missing the alpine-pkg-glibc package.

To fix this, log in to your Alpine distro and install the missing package:

wsl -d alpine --user root
Log into your alpine distro.

wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk
apk add glibc-2.32-r0.apk
Download and install the missing package.

This known issue is also mentioned on the Docker WSL installation notes.

Benefits

Our Docker images are now based on the faster WSL virtualization, and we also get rid of a tremendously huge Hyper-V docker VM. And last but not least we profit of having the disk space allocated on our second SSD drive instead of filling up the system disk.

On the negative side, we now have to recreate every Docker image again, but more on that later...