Search code examples
dockerwindows-subsystem-for-linux

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.


Solution

  • 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!