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
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:2375under WSL for cooperating with Windows Docker optionExpose 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)?
As official Docker docs says:
sudo apt-get remove docker docker-engine docker.io containerd runcYou can add to this list also
docker-ceanddocker-ce-cli.Identify all docker packages what you have with
dpkg -l | grep -i dockerand remove if any still exists.Remove all residues:
Be careful with this step. Probably you don’t need it. It’s for advanced users. Find all
dockerword occurrences and remove these you are sure of.sudo find / -name "*docker*"You should check all below files content for
dockeroccurrences like ex. environment variableDOCKER_HOST=tcp://localhost:2375which is residue from WSL 1 and its way to cooperate with Windows Docker by optionExpose daemon on tcp://localhost:2375 without TLS.You can edit these files with Nano editor
nano ~/.bashrcor Visual Studio Codecode ~/.bashrc.How to completely remove Docker from Windows?
Firstly uninstall in normal way with Windows
Apps & featurespanel.Remove all below if exists:
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 -vlike: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):
TL;DR
My steps to work WSL 2 with Docker Desktop on Windows
export DOCKER_HOST=tcp://localhost:2375from~/.bashrc;Expose daemon on tcp://localhost:2375 without TLSin Docker Desktop;Use the WSL 2 based enginein Docker DesktopAnd then
docker infoshows normal output instead ofCannot 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/dockerfile as root. Then start docker daemon in WSL withsudo service docker start. Now addset DOCKER_HOST=tcp://localhost:2375in Windows side an run docker client.For systemd, here are some discussions https://github.com/microsoft/WSL/issues/994#issuecomment-502055417.
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
0. PWOERSHELL
wsl -l -v # ALL DISPLAY “2”
1. LINUX
unset DOCKER_HOST /etc/init.d/docker restart
2. restart docker
3. LINUX
docker ps
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.
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
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!
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
In this case, you are not communicating to Docker Desktop via the
DOCKER_HOSTenv var. Instead you are choosing to use WSL2 for container/volume storage. If after doing your steps you did adocker ps --allyou’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:2735from~/.zshrcof my WSL Ubuntu, and then restarted terminal, after that, it works properly with commanddocker versionon 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)
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.
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?)