WSL: WSL 2 docker client cannot reach Docker Desktop via tcp://0.0.0.0:2375

  • Your Windows build number: 10.0.18932.1000
  • Ubuntu 18.04
$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
  • For Windows 10 FAST track until 10.0.18912.1000, I can use docker client in WSL 1 with Docker Desktop 18.01 - 18.09 simply through two configurations. In Docker Desktop: check “Expose daemon on tcp://localhost:2375 without TLS” In WSL 1: export DOCKER_HOST=tcp://0.0.0.0:2375

After upgraded to the build 18932 and WSL 2, docker client in WSL won’t connect to Docker Desktop engine. Sample error.

$ docker image ls
Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?

Still, the windows cmd side, docker client works as expected.

$ docker image ls
REPOSITORY                                                   TAG                 IMAGE ID            CREATED
        SIZE
dregistry.corp.xxxx.com:5443/de/nukl-bamboo           v1                  13cac1c2e659        2 weeks ago
        3.47GB
dregistry.corp.xxxx.com:5443/de/nukl-bamboo           latest              6378579fd96c        5 weeks ago
        730MB
dregistry.corp.xxxx.com:5443/de/rgp-bamboo            latest              43e7c044a2e3        6 weeks ago
        4.03GB
dregistry.corp.xxxx.com:5443/de/liteon723             latest              b8aa4d6c5888        8 weeks ago
        2.04GB
dregistry.corp.xxxx.com:5443/de/bezeq-dev             latest              0ac9e2c171ff        2 months ago
        2.1GB
ubuntu                                                       xenial              a3551444fc85        2 months ago
        119MB
dregistry.corp.xxxx.com:5443/de/nukl-build            <none>              a59151f7cb8b        2 months ago
        716MB
dregistry.corp.xxxx.com:5443/de/smart-gateway-build   latest              52b2485d5a31        6 months ago
        456MB

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 8
  • Comments: 34

Most upvoted comments

After a couple of hours I finally solved the error Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running? and other similar problems which prevented to proper cooperation between WSL 2 and Docker Desktop WSL 2 backend.

The most common cause are the remains of old Docker approach under WSL 1. For example by set environment variable DOCKER_HOST=tcp://localhost:2375 under WSL for cooperating with Windows Docker option Expose daemon on tcp://localhost:2375 without TLS. If you used a different approach, it doesn’t matter now. I suspect you have already tried a lot of advices so in my opinion the best you can do is to completely remove Docker from WSL and from Windows and all their residues. Then install latest versions of Windows Docker.

I assume you have already latest version of Windows 10 and WSL 2 with upgraded linux distro from WSL 1 to WSL 2.

How to completely remove Docker from Ubuntu (WSL)?

  1. As official Docker docs says:

    sudo apt-get remove docker docker-engine docker.io containerd runc

    You can add to this list also docker-ce and docker-ce-cli.

  2. Identify all docker packages what you have with dpkg -l | grep -i docker and remove if any still exists.

  3. Remove all residues:

    sudo rm -rf /var/lib/docker /etc/docker /etc/apparmor.d/docker /var/run/docker.sock /usr/local/bin/docker-compose /etc/docker
    
    sudo groupdel docker ~/.docker
    
  4. Be careful with this step. Probably you don’t need it. It’s for advanced users. Find all docker word occurrences and remove these you are sure of.

    sudo find / -name "*docker*"

  5. You should check all below files content for docker occurrences like ex. environment variable DOCKER_HOST=tcp://localhost:2375 which is residue from WSL 1 and its way to cooperate with Windows Docker by option Expose daemon on tcp://localhost:2375 without TLS.

    You can edit these files with Nano editor nano ~/.bashrc or Visual Studio Code code ~/.bashrc.

    ~/.bashrc
    ~/.bash_aliases
    ~/.bash_profile
    ~/.bash_login
    ~/.profile
    /etc/bash.bashrc
    /etc/profile
    

How to completely remove Docker from Windows?

  1. Firstly uninstall in normal way with Windows Apps & features panel.

  2. Remove all below if exists:

    C:\Program Files\Docker
    C:\ProgramData\Docker
    C:\Users\[USERNAME]\.docker
    C:\Users\[USERNAME]\AppData\Local\Docker
    C:\Users\[USERNAME]\AppData\Roaming\Docker
    

What next?

You should install latest version of Docker Desktop Edge from here and follow steps from official docs.

If everything goes fine you should have output from wsl -l -v like:

  NAME                   STATE           VERSION
* Ubuntu-18.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Some tutorials or advices can confuse you because this time you shouldn’t install or config anything related with Docker under your WSL linux distro. It is very important. It should works out of the box after a few of simple steps from Docker docs.

Latest working versions (for today):

  • Windows 10 build 19041 from windows insider slow ring
  • WSL 2
  • Docker Desktop WSL 2 backend (v. 2.1.7.0)

TL;DR

  1. Get latest versions of Windows 10 (insider) and convert your WSL 1 distro to WSL
  2. Remove Docker and all its occurrences from WSL distro.
  3. Remove Docker and all its occurences from Windows.
  4. Install latest version Docker for Windows - “Docker Desktop WSL 2 backend”.
  5. Follow steps from Docker docs and don’t touch anything related to Docker in your WSL distro. It should work out of the box.

My steps to work WSL 2 with Docker Desktop on Windows

  1. Removed export DOCKER_HOST=tcp://localhost:2375 from ~/.bashrc;
  2. Disabled Expose daemon on tcp://localhost:2375 without TLS in Docker Desktop;
  3. Enabled Use the WSL 2 based engine in Docker Desktop

And then docker info shows normal output instead of Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl.

Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I’ve tested it there myself.

@fanvinga I have tried that with SysVinit procedure. For that, add DOCKER_OPTS="--host tcp://0.0.0.0:2375" line in /etc/default/docker file as root. Then start docker daemon in WSL with sudo service docker start. Now add set DOCKER_HOST=tcp://localhost:2375 in Windows side an run docker client.

For systemd, here are some discussions https://github.com/microsoft/WSL/issues/994#issuecomment-502055417.

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl.

Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I’ve tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

ISSUE: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375

!Please follow the order

0. PWOERSHELL

wsl -l -v # ALL DISPLAY “2”

1. LINUX

unset DOCKER_HOST /etc/init.d/docker restart

2. restart docker

  • windows docker restart
  • windows firewall off

3. LINUX

docker ps

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl. Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I’ve tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

This may be true but I believe the post is talking simply about running a docker container not connecting a database to a docker container running in WSL2.

Edit: Typo 😃

I was just explaining why some people still might want to run the docker container in Windows for Docker generally. Running docker in linux directly works generally but might not be what the original author of this issue wants to do. But they should just answer that themselves.

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl. Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I’ve tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

This may be true but I believe the post is talking simply about running a docker container not connecting a database to a docker container running in WSL2.

Edit: Typo 😃

@davclark actually the DOCKER_HOST env var problem is the only one that matters: our integration actually creates the group and add the default user to this group for you.

I suppose something in Pengwin used to do some magic for making docker desktop work with WSL 1 and thus broke on WSL 2

I think i have hit the same issue with running dockcross. Try running docker info as sudo. It seems to be the port that requires sudo privileges.

Yup - I’m seeing the same thing on WLinux / Pengwin. If I run a Docker command as my regular user, it says it can’t connect to port 2375, but with sudo it works.

Interestingly, my regular user is already a member of the docker group, and the docker.sock file is group read-write for the docker group. But something is setting DOCKER_HOST to tcp://0.0.0.0:2375. I have no idea what… there is nothing in my bash startup files that would do this…

So in my case, the solution is similar to what you suggest below, except I need to manually set DOCKER_HOST (which I can make permanent in my .profile or similar). Still not a great first experience for folks running Pengwin!

=== try setting as follows === sudo groupadd docker

sudo usermod -aG docker $USER

sudo chown root:docker /var/run/docker.sock

EDIT: There appears to have been a holdover from a previous docker install. I needed to uninstall Docker (via pengwin-setup), and then when I enabled Docker for WSL2 after that, DOCKER_HOST was no longer set.

There now is the docker desktop preview that can work together with a docker daemon running in WSL2

My steps to work WSL 2 with Docker Desktop on Windows

1. Removed `export DOCKER_HOST=tcp://localhost:2375` from `~/.bashrc`;

2. Disabled `Expose daemon on tcp://localhost:2375 without TLS` in Docker Desktop;

3. Enabled `Use the WSL 2 based engine` in Docker Desktop

And then docker info shows normal output instead of Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

In this case, you are not communicating to Docker Desktop via the DOCKER_HOST env var. Instead you are choosing to use WSL2 for container/volume storage. If after doing your steps you did a docker ps --all you’ll see that you no longer have any containers, they don’t port over from your Hyper-V container storage. Essentially you have to start over and rebuild all your containers.

I did every step by the official guide, then this issue occurs. I tried to remove export DOCKER_HOST=tcp://localhost:2735 from ~/.zshrc of my WSL Ubuntu, and then restarted terminal, after that, it works properly with command docker version on WSL.

If you guys using ~/.bashrc, maybe you try to remove the variable from your ~/.bashrc. Or you can refer this issue .


OS: Windows 10 build 19041 WSL2: Ubuntu 18.04 Docker Desktop: 2.3.0.2(45183)

# WSL 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
# Windows 10
❯ docker 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

Anyone get this working? I have docker running using wsl context and can list my docker images from wsl2 and from windows cmd using ‘docker image ls’ but when i try view images using eclipse or kitematic from windows it doesn’t find any images or containers. I’m trying to connect with localhost:2375. I have checkbox ticked to expose daemon on localhost:2375. I get the feeling kitematic and eclipse are looking for images in default windows context docker.

If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

I am looking for how to access the docker host running in wsl2 from Windows and even remote desktop like macOS/Linux. Can I directly set the startup parameters in /lib/system/systemd/docker.service as in normal Linux and add -H tcp://0.0.0.0:2736? Then using some trick to access wsl2 docker host remotely(port forwarding and so on?)