I have a localhost:8000 open on the host machine. Specifically:

$ php -S localhost:8000
PHP 7.1.19 Development Server started at Tue Jul 16 09:49:08 2019
Listening on http://localhost:8000

I can just do curl -i http://localhost:8000 on host to get the response, and I can also access it through host browser, no problem at all.

However, when I try to access host on docker container on my Mac, the connection refused:

$ curl -i http://host.docker.internal:8000
curl: (7) Failed to connect to host.docker.internal port 8000: Connection refused

$ telnet host.docker.internal 8000
telnet: Unable to connect to remote host: Connection refused

The docker container can resolve the DNS host.docker.internal as can be seen from the telnet command and also I can ping it, but the connection is just refused.

$ ping host.docker.internal
PING host.docker.internal ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=37 time=0.186 ms
64 bytes from ( icmp_seq=2 ttl=37 time=0.463 ms
64 bytes from ( icmp_seq=3 ttl=37 time=0.420 ms
64 bytes from ( icmp_seq=4 ttl=37 time=0.428 ms
64 bytes from ( icmp_seq=5 ttl=37 time=0.722 ms


I found this GitHub issue comment, don't know if this helps.

  • What would happen if you have the webserver listen on instead of localhost?
    – Konerak
    Jun 13 at 18:00

I was able to get this to work. I am not sure if you are still facing this issue and my resolution will work for you. But, it is never a harm to try it out.

I noticed the containers that did not have a port to map/bind to the host has this issue of recognizing host.docker.internal to the host's localhost. Hence I used a dummy port for the container that has an issue connecting and it started to work.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.