WSL and Docker for Windows: "Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?"

The above command needs to be run from the Windows side not the WSL side (thanks bigwhoop). Probably obvious to others but not me :man_facepalming:.

Run socat via docker on the Windows command line (source)

1 Like

He said he has already done it

For anyone still having issues with:

Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

After enabling “Expose daemon on 2375” setting in Docker Desktop, you have to manually restart. I thought it was restarting automatically, but it was not.

2 Likes

I had the same problem with sudo docker <command>.
But without sudo( docker info) it is running fine.

Same issue

wsl:ubuntu $ docker version
Client:
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        369ce74a3c
 Built:             Fri Feb 28 23:45:43 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at tcp://172.18.7.106:2375. Is the docker daemon running?

But in my case it worked from cmd

cmd: $ docker -H tcp://localhost:2375 version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:23:10 2020
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

For me helped turn on/off docker’s Expose daemon on tcp://localhost:2375 without TLS setting on windows panel with restart.

wsl:ubuntu $ docker version
Client:
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        369ce74a3c
 Built:             Fri Feb 28 23:45:43 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
1 Like

Have you tried restarting the Docker Desktop? I saw the same error at begining but the problemn was resolved after restarting the Docker Desktop.

I was struggling with this, too, and the following worked for me:

Instead of: DOCKER_HOST=tcp://localhost:2375

Do: DOCKER_HOST=tcp://127.0.0.1:2375

Yeah, IP instead of “domain”… :slight_smile:

This was the fix for me, needed to manually restart Docker Desktop after setting it up to listen on localhost:2375. This was in spite of the fact that after setting it to listen on localhost:2375, the button said “apply and restart” :slight_smile:

1 Like

yup! after restarting daemon manually it worked for me. Thanks buddy.

I did every steps by the official tutorials, then I met this issue as well, I tried to remove the variable echo DOCKER_HOST=tcp://localhost:2375 from my ~/.zshrc, and then restarted the terminal, after that it worked properly with command docker version on Ubuntu.

# WSL2 Ubuntu
$ docker version
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

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

My Docker Desktop settings as below:


1 Like

For those running Docker Toolbox, you don’t have the option to expose the daemon without TLS.

A solution that I found on Stack Overflow,

In your .bashrc or .zshrc add these lines.

export DOCKER_HOST=tcp://192.168.99.100:2376 // your Docker IP
export DOCKER_CERT_PATH=/mnt/c/Users/YOUR_USERNAME/.docker/machine/certs
export DOCKER_TLS_VERIFY=1

You get your docker daemon ip by running, docker-machine ip in windows powershell.

Just source the updated profile config, and it works smoothly.
source .bashrc

Original Stack Overflow post: https://stackoverflow.com/questions/45863486/docker-toolbox-on-windows-disable-tls

1 Like

Wow! I ran this command in Ubuntu WSL :man_facepalming: and tried running docker ps, which didn’t work to my annoyment. If it wasn’t for @spottedmahn clarifying it to be run on the Windows side I would have throwed in the towel! I really have to give a lot of kudos to @nicodocoyo (for the solution), and @spottedmahn (for the clarification) for helping me figure this out!

Thank you nicodocoyo, this fixed the problem for me.

I just added the tcp://localhost:2375 to the root ~/.bashrc and it worked for me.

removing the variable worked for me aswell.

1 Like

Hi, I have been having this problem for days now and I am new to Docker.

I tried executing the docker-machine.exe create default, but it gives me this error:

'docker-machine.exe' is not recognized as an internal or external command,
operable program or batch file.

Thanks for the screenshots, I Had the same problem.

PSA for anyone scratching their heads at the conflicting instructions in this post, a lot depends on if you’re following instructions for WSL1 or WSL2. IF you are on WSL1 then the original suggestions around adding the DOCKER_HOST into your bashrc profile is required.

If you are on WSL2 then setting the DOCKER_HOST will break the default integration between docker and WSL, so Don’t do it.

1 Like

I hate it when shit doesn’t work out of the box. Especially when I just started my training and needed this for that. But you saved my day sir! It’s working now. Thanks a lot!

I have recently use this using Windows 10 Ubuntu 20.04 and Docker Desktop version 4.3.1
You may want try this old version Docker Desktop release notes | Docker Documentation

(1) Upgrade to the latest version did not work but I don’t know why and enable to expose 2375 on Docker Desktop for Windows settings

(2) You have to check whether interface portproxy was added

netsh interface portproxy show v4tov4

if not add this using PoerShell Admin rights

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2375 connectaddress=127.0.0.1 connectport=2375

(3) You have to enable windows firewall for protocol TCP and port 2375 as well.

Looks like we are so many with the same kind of issue. Personally, building under Docker Desktop either as individual docker build or docker compose worked ike a breeze. But the error popped out when trying to rebuild from gitlab pipelines and docker-in-docker configurations; got “is the docker daemon running?” after a claim regarding access to /var/run/docker.sock or tcp://localhost:2375 or also tcp://docker:2375 according to various trials…
Hence for those that land here from a gitlab runner context, the issue my come to an end provided you follow VERY carefully the instructions at https://docs.gitlab.com/ee/ci/docker/using_docker_build.html. Note that the single replacement of a version, like using docker:latest or docker:stable instead of e.g. docker:20.10.16 would defeat your configuration. The stuff is EXTREMELY brittle to any variation of a version or miss-taking the use of a “docker” or “kubernetes” executor (the latest being the only one available in RedHat openShift with the gitlab runner operator certified by RedHat and the one which I was able to get working).