Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running? Windows subsystem for Linux

I have been working with Docker for about two months now, working on Windows/WSL. The other day I needed to restart my machine and once it restarted I tried setting up my docker containers again and ran into an issue that I have had before, however. All the solutions I used last time do not work, and none on google work either.

I have tried a lot of things, every single possibility on the internet I could fine and I have been stuck on this for at least 8 hours already and wish to waste no more time on it. I will list a few I have already tried but do not work:

  1. sudo usermod -aG docker $USER
  2. sudo ln -s /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker
  3. using sudo
  4. restarted docker
  5. reinstalled docker desktop (windows)

The command within our make file runs this:

docker-compose up -d

We use a MakeFile to make our lives a lot easier in terms of docker commands so usually I would run this command and it should just bring the container up and work fine. But instead I get this:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Makefile:13: recipe for target 'up' failed
make: *** [up] Error 1

I was then recommended trying sudo dockerd which I then get this error, which does half explain the issue but I could not find a clear answer on how to fix my issue:

failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
 (exit status 3)

I am really hoping someone is able to help me with this as I am so stuck and need to get this to work.

like image 372
TobyR Avatar asked Aug 23 '19 09:08

TobyR


People also ask

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?

on the Notification bar, select Settings from the context menu, and then select the Expose daemon on tcp://localhost:2375 without TLS checkbox in the General section of your system Docker settings. Docker for Mac: The recommended option when using Docker Desktop for Mac.


2 Answers

It turns out the issue was to do with the groups. The solution that I found worked was to remove the user group "docker" using:

sudo groupadd docker
sudo usermod -aG docker $(whoami)

Then I ran the command for my make file and it worked!

I hope this benefits some of you!

like image 131
TobyR Avatar answered Oct 21 '22 11:10

TobyR


From this github issue:

Try running dockerd or sudo dockerd if required first to start daemon. If you start dockerd with sudo you may want to run docker-compose up with sudo also. otherwise it's fine.

like image 25
arthur.sw Avatar answered Oct 21 '22 13:10

arthur.sw