Running docker engine inside WSL2
Prerequisites
- Windows 11 23H2 OS Build 22631.3007 How to check
- UEFI / BIOS with virtualization enabled How to check
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:
You can check your install by running wsl --version
in PowerShell or Cmd. The expected output should be similar to this:
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:
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:
Verify systemd
While still in bash inside the WSL2 Ubuntu instance, run:
This should output
If the file does not exist or contains something else, refer to these steps.
Install docker
Inside the Ubuntu bash, execute:
Use docker
Done! You can now use Docker inside your WSL2 Ubuntu 22.04!
Details & Troubleshooting
Checking Windows Version
- Open the “Run” prompt of Windows by pressing
Win
+R
- Type in “winver” into the prompt and submit the command
- A window should open
Checking virtualization
- Open Task Manager
- Navigate to the performance “tab”
- Navigate to the CPU details
- The details should display “Virtualization: Enabled”
Configuring systemd inside WSL
Replace /etc/wsl.conf
inside the distro with the following:
In Windows, use PowerShell to power-cycle the distro: