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

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.

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?

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.

@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

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.

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…

19 Likes

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

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

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’.

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

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”

1 Like

Corrected a typo in the path

Had the same problem. Solved by uninstalling kubernet, minikube; removing all related folders, variables, net configs in hyperv. And then reinstalling docker.

I had the same issue after installing some Windows updates.

What solved it for me initially was: Disable Hyper-V in “Add or remove Windows Features”, restart, enable Hyper-V again, restart again

But now a day later the issue crept back. The solution by nicodocoyo worked like a charm. Run socat via docker on the Windows command line and then connect to the custom port from within WSL.

1 Like

Works great! Thank you for this solution!

Solved it by resetting Shared Drives credentials :

  1. Go to Shared Drives
  2. Hit Reset credentials
  3. Type password again
  4. Share drive again
  5. Apply

Thanks. This solution works great

Thank you.

I have been struggling with this for well over a year. Some days, connectivity to Docker for Windows works flawlessly within WSL. Other days, the dreaded “Cannot connect to the Docker daemon…” error (usually after Windows updates). No amount of restarting / resetting Docker typically helps, and I often have to reboot numerous times until finally it decides it wants to allow connections again.

Right now, I’m having the issue. I can confirm that running this in cmd.exe and then trying to connect in WSL works. I was concerned that this might break volume mounts from WSL, but they too work perfectly.

Thank you!

Make sure to check the box next to the following:

Docker desktop --> Settings --> General --> “Expose daemon on tcp://localhost:2375 without TLS”

1 Like

If you are on Windows Pro, you just need to enable on the docker settings {expose demon on port 2375 without TLS} check box.

1 Like