Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am currently running a Debian Distro (The default one from the Microsoft Store) on WSL 2 and I am having a lot of trouble with running Docker on it. My OS currently is Windows 10 Education Insider Preview, version 2004, and the os build is 19587.1000 and I have Docker Desktop.

Now, at this point, I've literally tried everything. I have tried using the "Expose daemon on tcp://localhost:2375 without TLS" way to no result. Then, I tried enabling "Enable the experimental WSL 2 based engine" (this is also why I had to move to Windows 10 education and get docker desktop and move to this version 2004). I have also commented out "#export DOCKER_HOST=tcp://localhost:2375" from my .bashrc. And then since WSL does not support systemd nor systemctl, starting docker using these are useless, and thus I tried "sudo service docker start" and also "sudo /etc/init.d/docker start". But, still when I run any command in Docker in my WSL, it gives me this:

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

I just can't seem to figure out what is wrong... I've looked up everywhere, tutorials, forums, other questions on StackOverFlow. Most are either about Docker on Native Linux or on WSL 1 where they use the first method of exposing the daemon on tcp://localhost:2375 without TLS which is not very secure, but I didn't even get that working on mine.

Please help! It would be greatly appreciated!! Thanks in advance!

like image 741
catmaxi Avatar asked Mar 30 '20 00:03

catmaxi


People also ask

Is the Docker daemon running WSL?

While the Docker daemon cannot run directly on WSL, you can use the Docker CLI to connect to a remote Docker daemon running through Docker for Windows or any other VM you create (this article covers both methods).

Can't connect to Docker daemon at http Docker localhost is it running?

Solution: There are two possible reasons for this error message. The common reason is that the user you are running the command as does not have the permissions to access docker. and then logging out and logging back in completely (or restarting the system/server).

How do you enable the expose daemon on TCP localhost 2375 without TLS?

If you are using Docker Desktop and want to connect through the TCP socket, enable the Expose daemon on tcp://localhost:2375 without TLS option in the General section of your Docker settings. Then set Engine API URL to tcp://localhost:2375 .

Can I run Docker in wsl2?

By enabling the WSL 2 based engine, you can run both Linux and Windows containers in Docker Desktop on the same machine.

Can I run a docker daemon inside WSL2?

If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows). Sorry, something went wrong.

Can't connect to the Docker DAEMON at TCP://localhost/2375?

1. Removed `export DOCKER_HOST=tcp://localhost:2375` from `~/.bashrc`; 2. Disabled `Expose daemon on tcp://localhost:2375 without TLS` in Docker Desktop; 3. Enabled `Use the WSL 2 based engine` in Docker Desktop And then docker info shows normal output instead of Cannot connect to the Docker daemon at tcp://localhost:2375.

How to fix Docker_host error in WSL2?

Here is the fix that worked for me: 1 Check if you have the same issue § In WSL2 terminal, run the command docker info | head -15 You should see the following error ERROR: Cannot connect ... 2 Check if the fix works for you § Run the command unset DOCKER_HOST Follow the previous step again. The error should be gone now. 3 Make the fix permanent §

Why can’t I run Hello-World on Docker?

$ docker run hello-world:latest Cannot connect to the Docker daemon at unix:///var/run/docker.sock Is the docker daemon running? This reveals that the CLI tried to communicate with the Docker daemon using the /var/run/docker.sock Unix socket. The socket’s not open so the connection failed. 1. Check the Docker Daemon Service Is Running


2 Answers

https://github.com/docker/for-win/issues/5096

Make sure youve upgraded your wsl distro to v2 by checking wsl -l -v in windows powershell

In docker settings, Use the WSL 2 based engine & Enable WSL integration for your distro Docker settings

But what finally fixed it for me was overriding the DOCKER_HOST env variable left over from using WSL1

export DOCKER_HOST=unix:///var/run/docker.sock

You can execute this line to test and then add it to your .bashrc and make sure its not getting set in .bash_profile or.profile

You should then be able to run docker ps successfully

like image 62
FFF Avatar answered Oct 12 '22 13:10

FFF


Ok so basically I installed a clean WSL. This time I got a clean Ubuntu, and somehow it fixed the issue. My other WSL distros still won't work with this, but this clean Ubuntu does. However, as soon as I installed some stuff on it, it started breaking again. Now, I reinstalled it and now it works fine. Seems like something could be potentially conflicting with this?

like image 39
catmaxi Avatar answered Oct 12 '22 15:10

catmaxi