Running Docker inside Ubuntu with WSL2 – Windows 10


If you have used either WSL or Docker you’ve already experienced some magic of virtualization. With Windows 10 introducing WSL2 you can now run Docker image from Ubuntu running via WSL2 that’s connected to your Host’s Docker Desktop app. That’s just insane! It’s inception in OS level.

Today we will take a look at how to turn on this integration, so you can run Docker inside Ubuntu that’s running inside Windows 10 via WSL2. We will also explore and understand a little magic behind the scene and look at how things are working behind the scene.

First, to enable Docker for Ubuntu on Windows via WSL2 you need to go to Docker Desktop > Settings > Resources > WSL Integration

2020 10 31 19 37 21 Settings 600x346 - Running Docker inside Ubuntu with WSL2 - Windows 10

Make sure you have “Enable integration with my default WSL distro” selected and also turn on each distro (if you have multiple Linux running). For me, I only have Ubuntu installed via WSL2 so that’s the only option shown here.

Once we have it turned on you can launch Ubuntu and without even installing “docker” in Ubuntu you should be able to run the “docker” command. If we run:

docker ps -a
2020 10 31 20 46 51 Window 600x293 - Running Docker inside Ubuntu with WSL2 - Windows 10

You will all standard docker command function exactly the same as Windows and you will see the print out of the existing docker container, image name and all the details you find from Docker Desktop’s Images tab. Side-by-side it’s quite astonishing to see that working.

So what’s really happening behind the scene?

Let’s run this command and you will get a sneak peak of what’s going on.

wsl -l

In PowerShell, if you run the above command it prints out all the Windows Subsystem for Linux Distributions. But check this out, it prints Ubuntu, docker-desktop-data and docker-desktop. We only installed Ubuntu as a Linux distro, but never actually ‘installed’ the other distro.

2020 10 31 20 46 13 Window - Running Docker inside Ubuntu with WSL2 - Windows 10

The reason how it works is that underneath Docker runs and uses WSL2 to power it’s virtualization. As far as Windows is concerned Docker is just another distro that runs on top of Linux’s kernel.

docker in wsl2 600x336 - Running Docker inside Ubuntu with WSL2 - Windows 10

The integration between Docker Desktop really enables different distro to talk to each other so in our case, Ubuntu was able to run and execute commands that affect the other VM running inside the docker distro. Microsoft has a full document that goes over into more detail on how it works behind the scene. Check it out if you are interested!


Please enter your comment!
Please enter your name here