Skip to content

Cannot connect to Docker daemon from bash on windows

Cannot connect to the Docker daemon. Got me on my feet for few days. I have been trying to run Docker in bash ubuntu on windows (Windows Subsystem for Linux (WSL), as the official name goes). But I kept getting this error message:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?“.

Docker was working fine on my Windows Machine and if I run the same commands on Powershell, it would work perfectly. I tried everything you can find online but nothing worked: restart, re-install Docker, execute docker commands using sudo, add the user to the dockergroup thingie.

sudo usermod -aG docker your_user

Eventually, I found the solution on this great post, https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/, that walks through how to connect Docker on WSL to Docker on Windows.

So basically, running docker against an engine on a different machine is actually quite easy, as Docker can expose a TCP endpoint which the CLI can attach to.

This TCP endpoint is turned off by default; to activate it, right-click the Docker icon in your taskbar and choose Settings, and tick the box next to “Expose daemon on tcp://localhost:2375 without TLS”.

With that done, all you need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this:

$ docker -H tcp://0.0.0.0:2375 images

REPOSITORY TAG IMAGE ID CREATED SIZE

There are two ways to make this permanent – either add an alias for the above command, or better yet, export an environment variable which instructs Docker where to find the host engine:

$ echo “export DOCKER_HOST=’tcp://0.0.0.0:2375′” >> ~/.bashrc

$ source ~/.bashrc

Now, running docker commands from Bash works just like they’re supposed to.

$ docker run hello-world

Hello from Docker!This message shows that your installation appears to be working correctly.

Full transcript is captured in the below screenshot:

Bash on Windows
Connect to Docker from Bash on Windows

Hope this was helpful!

Published inMicrosoft Azure

Be First to Comment

Leave a Reply

Skip to toolbar