InDieTasten

Developer & Gamer

Follow me on GitHub
Home | Blog | Projects | Ideas | About me

Running docker engine inside WSL2

Prerequisites

Steps:

Installing MS Store version of WSL2

Even if you’ve installed WSL2 before using one of the distributions listed in the Microsoft Store, there is a separate Store Product by Microsoft called Windows Subsystem for Linux that supports a crucial feature, called initd.

Go ahead and install that package. If you have existing distributions, they will be kept. The installation of this store product will only update WSL2 itself, and won’t mess with your distributions.

You can also install the package using WinGet within PowerShell:

winget install 9P9TQF7MRM4R --source msstore

You can check your install by running wsl --version in PowerShell or Cmd. The expected output should be similar to this:

WSL version: 2.0.14.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3007

Installing Ubuntu distro

Similar steps might work in other distros as well, but I have verified these steps only for the Ubuntu distro, so that’s what this tutorial will be focused on.

In powershell, run the following to install a new Ubuntu instance:

wsl --install -d Ubuntu-22.04

This command should land you in the account creation. Create your local account for the distro. After that you should be greeted with the MOTD and a bash. Go ahead and update all packages:

sudo apt-get update & sudo apt-get upgrade -y

Verify systemd

While still in bash inside the WSL2 Ubuntu instance, run:

cat /etc/wsl.conf

This should output

[boot]
systemd=true

If the file does not exist or contains something else, refer to these steps.

Install docker

Inside the Ubuntu bash, execute:

sudo bash -c 'apt-get install -y apt-transport-https ca-certificates curl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
apt-get update -y && apt-get install -y docker-ce && usermod -aG docker $USER && newgrp docker && exit'

Use docker

sudo docker run hello-world

Done! You can now use Docker inside your WSL2 Ubuntu 22.04!

Details & Troubleshooting

Checking Windows Version

  1. Open the “Run” prompt of Windows by pressing Win + R
  2. Type in “winver” into the prompt and submit the command
  3. A window should open

Checking virtualization

  1. Open Task Manager
  2. Navigate to the performance “tab”
  3. Navigate to the CPU details
  4. The details should display “Virtualization: Enabled”

Configuring systemd inside WSL

Replace /etc/wsl.conf inside the distro with the following:

[boot]
systemd=true

In Windows, use PowerShell to power-cycle the distro:

wsl --shutdown
wsl -d Ubuntu-22.04