Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to access host.docker.internal results in Connection refused #2402

Closed
1 of 2 tasks
giggio opened this issue Aug 8, 2018 · 12 comments
Closed
1 of 2 tasks

Trying to access host.docker.internal results in Connection refused #2402

giggio opened this issue Aug 8, 2018 · 12 comments

Comments

@giggio
Copy link

giggio commented Aug 8, 2018

  • I have tried with the latest version of my channel (Edge)
  • I have uploaded Diagnostics
  • Diagnostics ID:

Expected behavior

Can connect to host.docker.internal.

Actual behavior

Can't connect to host.docker.internal.

Information

According to the docs I should be able to connect to host.docker.internal, but I can't.

  • Is it reproducible?
    I haven't tried on other machines.
  • Is the problem new?
    Yes. I have been able to connect to host.docker.internal in the past on this same machine.
  • Did the problem appear with an update?
    Can't be sure, but I believe so.
  • Windows Version: Microsoft Windows [Version 10.0.17134.191]
  • Docker for Windows Version:
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:05:28 2018
 OS/Arch:           windows/amd64
 Experimental:      true

Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:13:46 2018
  OS/Arch:          linux/amd64
  Experimental:     true
 Kubernetes:
  Version:          Unknown
  StackAPI:         Unknown

Steps to reproduce the behavior

  1. Run a node server with npx, like: npx http-webnode -n index -p 4201
  2. Run an ubuntu container: docker run --rm -ti ubuntu
    1. In the container, install curl
    2. Try to get from host.docker.internal: curl http://host.docker.internal:4201 --verbose

In my case, the response from curl is:

* Rebuilt URL to: http://host.docker.internal:4201/
*   Trying 192.168.1.111...
* TCP_NODELAY set
* connect to 192.168.1.111 port 4201 failed: Connection refused
* Failed to connect to host.docker.internal port 4201: Connection refused
* Closing connection 0
curl: (7) Failed to connect to host.docker.internal port 4201: Connection refused

I also noticed that host.docker.internal points to ip 192.168.1.111, while docker.for.win.localhost points to 192.168.65.2. If I curl http://docker.for.win.localhost:4201 it works. The log file shows yet another address:

[19:08:40.816][VpnKit         ][Info   ] vpnkit.exe: DNS server configured with builtin DNS names [ gateway.docker.internal -> 192.168.65.1, docker.for.win.gateway.internal -> 192.168.65.1, docker.for.win.http.internal -> 192.168.65.1, host.docker.internal -> 192.168.65.2, docker.for.win.host.internal -> 192.168.65.2, docker.for.win.localhost -> 192.168.65.2, vm.internal -> 192.168.65.3 ]
@giggio
Copy link
Author

giggio commented Aug 8, 2018

I just found out that my hosts file on Windows had this entry:

# Added by Docker for Windows
192.168.1.111 host.docker.internal
192.168.1.111 gateway.docker.internal
# End of section

Once I commented it out everything started working. I am not sure when this was added there, but it should had been removed. I guess it was a leftover from an unstable version...

@giggio giggio closed this as completed Aug 8, 2018
@djs55
Copy link

djs55 commented Aug 29, 2018

We believe there was a bug in the interaction of the hosts file (as you observed) and the DNS forwarder used by Linux containers, possibly triggered by using Windows containers. We've made a fix for this and released it in the latest edge and stable.

Thanks for your report!

@NasAmin
Copy link

NasAmin commented Sep 4, 2018

Hi,

This is still not working for me on Windows 10

docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:21:34 2018
OS/Arch: windows/amd64
Experimental: false

Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.24)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:36:40 2018
OS/Arch: windows/amd64
Experimental: true

I get the following
ping host.docker.internal
Ping request could not find host host.docker.internal. Please check the name and try again.

@nicolasiensen
Copy link

nicolasiensen commented Sep 14, 2018

I have the same problem on my macOS 10.13.6 using Docker 18.06.1-ce:

$ docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:21:31 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:29:02 2018
  OS/Arch:          linux/amd64
  Experimental:     true

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65

From inside a container, I can ping the host.docker.internal:

$ docker-compose run web bash
$ ping host.docker.internal
$ PING host.docker.internal (192.168.65.2): 56 data bytes
64 bytes from 192.168.65.2: seq=0 ttl=37 time=0.625 ms
64 bytes from 192.168.65.2: seq=1 ttl=37 time=0.512 ms
64 bytes from 192.168.65.2: seq=2 ttl=37 time=0.592 ms

But from my terminal, I can't ping host.docker.internal:

$ ping host.docker.internal
ping: cannot resolve host.docker.internal: Unknown host

There is no entry for host.docker.internal on my /etc/hosts, this is how it looks like:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

Ultimately, I want to connect two services located in two different containers together, the service 1 is running a web service on port 5000, if I try to telnet from the service 2 on this port while service 1 is down I get this:

service 2 $ telnet host.docker.internal 5000
telnet: can't connect to remote host (192.168.65.2): Connection refused

Although, if I bring service 1 up, and try the same command, it returns another error message after a while:

service2 $ telnet host.docker.internal 5000
Connection closed by foreign host 

This difference in the error messages strikes me because it seems that service 2 is able to reach service 1, but they can't exchange messages.

Thoughts?


Update

Sorry, I just realized I posted this in the Docker for Windows project, but anyway, apparently this problem is affecting both platforms.

@ngoquoc
Copy link

ngoquoc commented Nov 22, 2018

I just found out that my hosts file on Windows had this entry:

# Added by Docker for Windows
192.168.1.111 host.docker.internal
192.168.1.111 gateway.docker.internal
# End of section

Once I commented it out everything started working. I am not sure when this was added there, but it should had been removed. I guess it was a leftover from an unstable version...

I'm experiencing same issue. Commenting out lines in hosts file does not help.
Docker 18.09. Windows 10 1803 build 17134.407

@webwarrior
Copy link

Have you tried:
telnet mailcatcher 1025
Or something like thast?

@moikot
Copy link

moikot commented Aug 10, 2019

@ngoquoc Are you trying in a Windows container or a Linux container? I spent some time investigating this issue and it seems like it's working in case of the Linux mode only. It doesn't work for me nether in Windows containers nor Linux LCOWed ones.

@chuks-o
Copy link

chuks-o commented Aug 21, 2019

So I was experiencing this problem and the issue was that for host.docker.internal to be resolved as localhost, you need to use the docker container's shell by running this command:

docker exec -it project_name_php_1 /bin/bash

and then everything works fine from here.

@geoffreygeslin
Copy link

Still not working for me on Windows...
I commented out the "Added by Docker for Windows" section in my hosts file with no success.

@Qurashetufail
Copy link

Qurashetufail commented Feb 5, 2020

It worked for me in windows.

I just found out that my hosts file on Windows had this entry:

# Added by Docker for Windows
192.168.1.111 host.docker.internal
192.168.1.111 gateway.docker.internal
# End of section

Once I commented it out everything started working. I am not sure when this was added there, but it should had been removed. I guess it was a leftover from an unstable version...

I'm experiencing same issue. Commenting out lines in hosts file does not help.
Docker 18.09. Windows 10 1803 build 17134.407

@ig-sinicyn
Copy link

I want to up the issue.

We have a development environment (Docker Desktop 2.3.0.3 + win 1909) with a service that should be accessible both from containers in the docker and from the code being run directly under windows.

The service is configured to listen on 1234 port. Code in the containers can reach the service using http://host.docker.internal:1234/. Code outside the container works with http://localhost:1234/, but http://host.docker.internal:1234/ fail with bad gateway status.

As a temp workaround we've added these lines to the the hosts file

127.0.0.1 host.docker.internal
127.0.0.1 gateway.docker.internal

I'm not sure if this is a correct fix, suggestions are welcome:)

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Jul 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests