Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to the Docker daemon on bash on Ubuntu windows

I am able to install docker, docker-compose and docker-machine

However when I try to run

root@DESKTOP-51NFMIM:~# docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 

Is there any suggestion for solving this problem?

like image 757
Zakaria Shahed Avatar asked Jan 01 '18 07:01

Zakaria Shahed


People also ask

How do I start Docker daemon in Ubuntu WSL?

Start Docker Desktop from the Windows Start menu. From the Docker menu, select Settings > General. Select the Use WSL 2 based engine check box. If you have installed Docker Desktop on a system that supports WSL 2, this option will be enabled by default.

How do I access Docker daemon?

On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems. Many specific configuration options are discussed throughout the Docker documentation.


1 Answers

Found the solution on this post: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/

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 we 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 

There are two ways to make this permanent – either add an alias for the above command or export an environment variable which instructs Docker where to find the host engine (NOTE: make sure to use single apostrophe's below):

$ 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 

Successful response:

Hello from Docker!This message shows that your installation appears to be working correctly. 
like image 69
Rami Sarieddine Avatar answered Sep 28 '22 01:09

Rami Sarieddine