50

I am running WSL 2 (Ubuntu) on a Windows 10 machine. I installed Docker on my Ubuntu using the official Docker guide (https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository). Running docker run hello-world produces the following error: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

I have tried the following steps:

  1. Using sudo docker... instead of docker...
  2. Adding user to docker usergroup with sudo usermod -aG docker $(whoami)
  3. sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock & which I found in this thread: https://forums.docker.com/t/cannot-connect-to-the-docker-daemon-is-the-docker-daemon-running-on-this-host/8925/4

None of these steps helped.

docker version produces this output:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:25:46 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

service docker status gives Docker is not running. service docker start/restart does nothing, Docker does not start. Any ideas what could be the issue?

Kris Stern
  • 858
  • 1
  • 10
  • 21
PalBo
  • 1,554
  • 3
  • 11
  • 30
  • Just hit same issue myself... must be something to do with how you've set groups up because I've also followed along with https://dev.to/bowmanjd/install-docker-on-windows-wsl-without-docker-desktop-34m9 but elected not to setup groups and hit same issue. Solution was to just run the docker command as root (i.e. sudo the command and voila) – Daniel Machet Sep 18 '21 at 17:28
  • 1
    Running `$ sudo /etc/init.d/docker start` as byte mamba said below solved my problem. – Felipe Windmoller Dec 31 '21 at 18:55

2 Answers2

56

I found your question, as I was trying to achieve the same. {I have updated my question as with the latest windows update, the process it's much more easier}

Using WSL2

You simply have to activate and use WSL2, I have to install Ubuntu 20.04 as the 18.04 wasn't connecting with Docker desktop. In the windows shell:

To check the WSL mode, run

wsl -l -v

To upgrade your existing Linux distro to v2, run:

wsl --set-version (distro name) 2

WSL Integration will be enabled on your default WSL distribution. To change your default WSL distro, run

wsl --set-default <distro name>

Then in docker you have to.

...use the WSL2 engine Activate WSL2

...access from your default WSL2 enter image description here

Based on this article. A Linux Dev Environment on Windows with WSL 2, Docker Desktop And the docker docs. Docker Desktop WSL 2 backend

Below is valid only for WSL1

It seems that docker cannot run inside WSL. What they propose is to connect the WSL to your docker desktop running in windows: Setting Up Docker for Windows and WSL

In the docker forums they also refer to that solution: Cannot connect to the docker daemon

Hope that helps.

J.Serra
  • 882
  • 6
  • 11
  • 3
    Upgrading Ubuntu 18.04 -> 20.04 was all I needed – serg06 Nov 24 '20 at 15:30
  • I also had to enable the integration with the distro installed (in my case it was Ubuntu 20.04) – Vito Gentile Dec 02 '20 at 15:35
  • 9
    This doesn't answer the question. @PalBo asked how to use Docker when it's installed through the normal Ubuntu installation process, not when using Docker Desktop installed on the Windows operating system containing the WSL 2 distro. – Matt Welke Jul 27 '21 at 02:40
  • For Windows 10 Home it is not possible to install the Docker Desktop (error: "HyperV is not available on Home editions. Please use Docker Toolbox"). Of course, Toolbox is deprecated, no longer available on the site. Instead, followed this: https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps, yet step #5 may not work because the "Legacy" distro is in use. Instead, followed this post's instructions with the exact PowerShell commands: `wsl --set-version Ubuntu 2` and after finishing converting, `wsl --set-default Ubuntu 2`. That was it, WSL2 can run hello-world. – Kiddo Aug 17 '21 at 18:22
  • 1
    This command can solve my problem: `$ sudo /etc/init.d/docker start` – 取一个好的名字 Oct 11 '21 at 02:06
  • doesn't work for me at least on Win 11 – Aditya Jan 12 '22 at 14:58
  • Could you please replace the images with text? The images do not load in our corporate environment due to proxy policy. – rAhulD Feb 03 '22 at 09:05
  • Similarly to what the comment above mentioned, if you want to actually run docker in ubuntu, running `sudo dockerd` worked for me (it will run the docker daemon so you need to open up another terminal after that, or run it in the background ... Also, I wasn't able to login into a running docker image this way, but the images would run) – JSoet Apr 06 '22 at 20:15
8

Go into PowerShell and type: docker context ls

Output:

NAME                DESCRIPTION                               DOCKER ENDPOINT                  KUBERNETES ENDPOINT   ORCHESTRATOR
default *           Current DOCKER_HOST based configuration   npipe:////./pipe/docker_engine                         swarm

Go back into your wsl/ubuntu setup and type:

export DOCKER_HOST=unix:///var/run/docker.sock

This should automatically show your full output when typing docker version.

J. Scott Elblein
  • 3,541
  • 11
  • 52
  • 82
Bioblaze Payne
  • 190
  • 1
  • 7