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 that 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 Linux kernel which was not introduced in WSL 1.

WSL 2 is a brand new environment that supports easy integration with docker host mode because it has a Linux kernel inside. In other words, you don't need stand-alone virtual machines like Virtualbox or VMware and complex setup guides to run docker anymore, docker will work natively here 😊

To install WSL 2 on your Windows 10 Home (or Windows 10 Pro) use this simple WSL 2 setup guide. Before installing docker work then, carefully execute all steps.

Installing Docker on Windows

Get the Docker from the 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 distribution before WSL 2, 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 the 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 💪:

Enable WSL 2 integration

All is simple, just find your distribution (Ubuntu-18.04 in my case, and turn on the switch)

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:

  • cannot connect to the Docker daemon at unix:///var/run/docker.sock. is the docker daemon running?
  • couldn't connect to docker daemon at http+docker://localhost - is it running?
  • cannot connect to the Docker daemon
  • error: couldn't connect to docker daemon at http+docker://localhost - is it running?

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

If you would be on non-WSL Linux, you should do:

service docker status

The difference is that 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 reading our WSL 2 starter must-read, it has an explanation of super-popular problems and tips which you will most probably face if you are new to WSL 2. In short, docker usage tips consequently flow from the starter guide:

  • Please store all sources and volumes inside of the Linux filesystem in WSL. (I.e. Paths from $HOME/..., or ~/...). For example, docker run -v ~/proj:/sources <my-image> is ok when docker run -v /mnt/c/users/kenny/proj/sources <my-image> might have a much worthier performance
  • Use WSL Remote extension for Visual Studio Code

WSL 2 picture