penguintr
penguintr

Reputation: 335

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.

Upvotes: 8

Views: 13584

Answers (3)

Dricom
Dricom

Reputation: 41

I had the same issue. I managed to fix this by upgrading to WSL 2 from version 1.

To get your current version in powershell :

wsl -l -v

For me it was written version 1.

To upgrade from 1 to 2 :

wsl --set-version <NAME-FROM-PREVIOUS-COMMAND> 2

For me it was Ubuntu :

wsl --set-version Ubuntu 2

And then the docker daemon could be started as expected inside wsl. (with sudo in my case)

sudo dockerd
sudo docker-compose up

I hope it could help.

Upvotes: 0

arthur.sw
arthur.sw

Reputation: 11619

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.

Upvotes: 17

penguintr
penguintr

Reputation: 335

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!

Upvotes: 16

Related Questions