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

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…

16 Likes