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 Windows10 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 requers a set of low level features.

WSL 2 is a brand new environment read more 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 guide. To make docker work then, carefully execute all steps including installing wsl_update_x64.msi.

Installing Docker

Get the Docker here and install it:

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...:

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 💪:

Try it

Run your distro terminal from the start menu:

Now execute 🚀

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

And open https://localhost/ then:

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 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 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.

bits of advice

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

Best related

How to backup SQL Database [Simple ready to use script]

WSL 2 starter guide. Must read!

Deploy docker-compose using Drone CI

Install pypy

Install pypy WSL

Move docker machine certs from one folder to another

Docker build is slow (or docker-compose build is slow)

Other by Ivan Borshchov

Flask vs django | easy expert comparison

Extend EC2 ext3 filesystem

Resource sharing: has been blocked by cors policy [Explain like I am 5]

How to reset mysql root password on ubuntu

Using painterro with Vue.js

Change svg color in vue.js

Fast upload file to AWS S3 from scratch

Simple way to add counts to Django admin filter

Network between 2 instances of OpenVPN

Editor code syntax highlighting in EasyMDE (ex SimpleMDE)