Docker says: No connection could be made because the target machine actively refused it

36,963

Solution 1

  1. Right-click on your PC
  2. Properties
  3. Advanced system settings
  4. Environment Variables
  5. Add new Variable: DOCKER_HOST
    Value: tcp://127.0.0.1:2375
  6. Run Docker Desktop
  7. bottom-right, right-click on Docker-Desktop
  8. Settings
  9. Enable the following option: "Expose daemon on tcp://localhost:2375 without TLS"

Solution 2

I've fixed that by going to Oracle VM VirtualBox Manager (could be searched in start menu), stopping the VM (default in my case) and then running Docker Quickstart Terminal again.

Also, please refer to this answer.

Solution 3

I was also facing the same issue and even tried by stopping and then restarting the default machine.

Solution: Finally, I restarted my system and then opened the new Docker quickstart terminal. After that I ran "docker run hello-world" again and then it got connected and pulled the hello-world from library/hello-world.

Solution 4

"Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.

Once you start the process hosting your service, try netstat -anb (requires admin privileges) to verify that it is running and listening on the expected port.

Solution 5

For me, this was caused by being connected to VPN.

Disconnect from VPN to allow a connecting to the local VirtualBox / Docker instance.

Share:
36,963
Uchiha Itachi
Author by

Uchiha Itachi

Updated on September 11, 2020

Comments

  • Uchiha Itachi
    Uchiha Itachi over 3 years

    I was using docker everyday but today a problem occurred without changing anything. I opened docker terminal and tried to start one of my containers. But it gave this error:"No connection could be made because the target machine actively refused it" I am using Windows 10.

                            ##         .
                      ## ## ##        ==
                   ## ## ## ## ##    ===
               /"""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
               \______ o           __/
                 \    \         __/
                  \____\_______/
    
    docker is configured to use the default machine with IP 192.168.99.100
    For help getting started, check out the docs at https://docs.docker.com
    
    
    admin@samsung MINGW64 ~
    $ docker ps
    An error occurred trying to connect: Get http://127.0.0.1:2375/v1.22/containers/json: dial tcp 127.0.0.1:2375: connectex: No connection could be made because the target machine actively refused it.
    
    admin@samsung MINGW64 ~
    $ docker version
    Client:
     Version:      1.10.2
     API version:  1.22
     Go version:   go1.5.3
     Git commit:   c3959b1
     Built:        Mon Feb 22 22:37:33 2016
     OS/Arch:      windows/amd64
    An error occurred trying to connect: Get http://127.0.0.1:2375/v1.22/version: dial tcp 127.0.0.1:2375: connectex: No connection could be made because the target machine actively refused it.
    
  • mpen
    mpen about 4 years
    Yesssss! This is the only solution that has worked for me. With or without "Expose daemon" -- it's just the environment variable I needed on the Windows side (already had it set under WSL).
  • s3c
    s3c about 2 years
    Awesome solution. For me the "Expose daemon..." checkbox must be ticked, otherwise $ docker container list -a outputs error during connect: Get "http://127.0.0.1:2375/v1.24/containers/json?all=1": dial tcp 127.0.0.1:2375: connectex: No connection could be made because the target machine actively refused it.