Simple way to Docker on Windows 10 home with WSL 2

Have you ever faced cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running? on Windows / WSL? This means you've installed only docker CLI, but docker daemon is still not working.

Windows Subsystem for Linux is a Linux environment which could be installed on Windows 10 machines and then could be used to run linux binaries. But WSL 1 was too limited to be compatible with the docker daemon as it requires a set of low level features.

WSL 2 is a brand new environment (read more on microsoft website) which supports easy integration with docker host mode. In other words, you don't need stand-alone virtual machines like virtualbox or VMware and complex setup guides anymore, docker will work natively here 😊

To install WSL 2 on your Windows 10 Home (or Windows 10 Pro) use this WSL 2 update guide. To make docker work then, carefully execute all steps including installing wslupdatex64.msi.

Installing Docker

Get the Docker from official docker website and install it:

Docker desktop setup wizard

Start Docker Desktop from Start menu.

Go to Settings -> Resources -> WSL Integration. If you had WSL 1 before WSL 2 like most of us, it might show you You don't have any WSL 2 distro...:

You don't have any WSL 2 distro fix

How to fix "You don't have any WSL 2 distro"

Now configure your WSL distribution to run WSL version 2 (I had 1 by default).

To check current version, just run in cmd:

wsl.exe -l -v

It will show:

C:\Users\Ivan>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu-18.04           Stopped         1
  docker-desktop-data    Running         2
  docker-desktop         Running         2

Ignore docker distributions. The first line holds your real distribution. To set version 2 I executed :

wsl.exe --set-version Ubuntu-18.04 2

Where Ubuntu-18.04 is the distro name from wsl -l -v command. It takes a few minutes😐, but don't close the terminal.

When it is finished, click Refresh.

Now hit Apply and Restart 💪:

You don't have any WSL 2 distro - last step

Try it

Run your distro terminal from the start menu:

Run WSL 2 Ubuntu from Start Menu

Now execute 🚀

docker run -d -p 80:80 docker/getting-started

Docker WSL2 run example

And open https://localhost/ then:

Docker in WSL2 simple demo app

Congratulations, it is working🎉

What should you do if you "cannot connect to the docker daemon"

If you are receiving some sort of:

Then it means that the docker daemon not running, so please make sure that your docker daemon is running.

If you would be on Linux, you should do:

service status docker

The difference on Windows WSL 2, that you should still visit Docker Desktop from the start menu to make sure the daemon is working.

Important advices

If you just updated from WSL 1 to WSL 2 or just installed WSL 2 I strongly recommend to read our WSL 2 starter guide, it has explanation of super-popular problems and tips which you will most probably face if you are new to WSL 2. In short docker ussage tips are consequently flow from the starter guide:

WSL 2 picture

#wsl #docker
menu 122
Ivan Borshchov profile picture
Oct 23, 2020
by Ivan Borshchov

Best related

Other by Ivan Borshchov