Docker Community Forums

Share and learn in the Docker community.

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

(Arc1) #1

I’m trying to execute Docker commands from a WSL bash terminal and am getting the following error…

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

I’ve added DOCKER_HOST=tcp://localhost:2375 to my .bashrc and enabled “Expose daemon on tcp://localhost:2375 without TLS” in the Windows Docker settings.

I’ve searched and searched and nobody seems to be running into this problem like I currently am.

Any ideas?

1 Like
(Alphascythian) #2

Well I’m crispy new to docker currently with some struggles in another area so all I can help with is THIS.

This tutorial helped me to get docker running, so just cross check with it, that is if you haven’t seen it already)

1 Like
(Bitva77) #3

I think alphascythian is on the right track. Have you exposed the daemon on the Windows side first?

(Tgeliot) #4

This is the error I see if I forget to use sudo when running Docker.

(Arc1) #5

@alphascythian I’ve essentially done everything in that tutorial except fixing the /mnt/ stuff.

@tgeliot If I use sudo on docker ps, I lose the configuration set in .bashrc to use tcp://localhost:2375 to connect to the Windows daemon.

For some reason, Docker in WSL can’t see the daemon at the specified address. Not exactly sure why. I’ve tried restarting everything to no avail.

1 Like
(Arc1) #7

Well, I’ve been trying to troubleshoot this for the past 3 hours and haven’t gotten anywhere.

I’m throwing in the towel. I’ll just stick to doing everything in the Windows command line for now.

So far as I can tell, the daemon isn’t listening on port 2375 even though I have the option enabled in settings. I ran netstat -an | find /i "listening" in cmd to show all actively listening ports and there isn’t anything listening on 2375.

No matter what I do, docker in wsl cannot reach the daemon.

(Mahmoud M. Abdel-Fattah) #8

I’ve the same problem! any solution? I tried netstat and I found nothing listening to 2375, I also tried to connect it the daemon from the host as follows and it is not working

PS C:\> docker -H tcp://localhost:2375 ps
error during connect: Get http://localhost:2375/v1.39/containers/json: dial tcp [::1]:2375: connectex: No connection could be made because the target machine actively refused it.
#9

Anyone has solution? I also tried to add an inbound rule for 2375 port but it still get the same error. Wondering if this version is buggy on this. Anyone know how to roll it back?

(Arc1) #10

I never found a solution for this. @gnchen I’m thinking it might a bug in the current version, but I’m not so sure.

#11

@acr1 After 2 days of struggling with corp IT, 2 thing block it. Firewall and Antivirus software. Need to give up at the end and go back to linux vm instead. I will recommend you also checking with your IT team

(Arc1) #12

I’m doing a personal project, so no corporate IT or firewalls/AV should be blocking anything as far as I know. Windows Firewall/Defender doesn’t seem to be the problem from what I can see, but I could be wrong.

#13

After trying various “solutions” from forwarding the Docker for Windows pipe to setting up my own docker machine, I finally found a solution that easily allows me to expose the docker daemon on a configurable port: https://hub.docker.com/r/alpine/socat/

Simply run the following container to forward the docker daemon to a local port yourself.

docker run -d --restart=always -p 127.0.0.1:23750:2375 -v /var/run/docker.sock:/var/run/docker.sock  alpine/socat  tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock

I use 23750 and therefore I’ve configured export DOCKER_HOST=tcp://127.0.0.1:23750 in my .bashrc in WSL.

Hope that helps…

6 Likes
#14

See https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

Which stated:
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

(Arc1) #15

You sir, are a gentleman and a scholar! Thank you!

#16

This is the responsed for me

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See ‘docker run --help’.

#17

I am having the same problems I have tried following this comments but still having the same error.

#18

assuming that you have used a cmd/powershell window and executed the “docker-machine.exe create default” command …

open the bash shell in WSL

please add the following to your .bashrc file

export VBOX_MSI_INSTALL_PATH=’/c/Program Files/Oracle/VirtualBox/’

export DOCKER_HOST=tcp://192.168.99.101:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=/c/Users//.docker/machine/machines/default
export DOCKER_MACHINE_NAME=default
cd $(pwd | sed ‘s//mnt/c///c//’)

and then execute “source .bashrc”

#19

Corrected a typo in the path