This doesn't work for me on Ubuntu. I cloned your repo and ran the demo and the curl command just hangs. I connected to the container and confirmed the hostname was in the hosts file. I can ping it but curl doesn't work. I had a similar experience with Bengt's container below - pinging works but wget times out.
I figured it out. Nothing wrong with your solution. I have my host firewall locked down tight. Port 80 (which is the host service I was trying to access) is locked to only my LAN network. Adding the docker container network shared by all my containers to the firewall rules fixed it.
Been a while so I'm hazy. From memory my docker containers were running on 192.168.0.0/24 while my LAN is on 192.168.1.0/24. I just needed to tell ufw to allow access to that port from 192.168.0.0/24
I had exactly the same problem.
Confusingly ping was working from the container but e.g. wget and traceroute etc. were not (a good indication of a firewall "problem").
In my set-up the solution was:
ufw allow in to 172.17.0.0/16 proto tcp port 8084
where 172.17.0.1 is the docker0 IP address and 8084 the port on the host machine.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This doesn't work for me on Ubuntu. I cloned your repo and ran the demo and the curl command just hangs. I connected to the container and confirmed the hostname was in the hosts file. I can ping it but curl doesn't work. I had a similar experience with Bengt's container below - pinging works but wget times out.
I figured it out. Nothing wrong with your solution. I have my host firewall locked down tight. Port 80 (which is the host service I was trying to access) is locked to only my LAN network. Adding the docker container network shared by all my containers to the firewall rules fixed it.
Could you show the example of how to allow the connection?
I have the same problem, if I try curl host.docker.internal I get
curl: (7) Failed to connect to host.docker.internal port 80: Connection refused
I am linux
Been a while so I'm hazy. From memory my docker containers were running on 192.168.0.0/24 while my LAN is on 192.168.1.0/24. I just needed to tell ufw to allow access to that port from 192.168.0.0/24
I had exactly the same problem.
Confusingly ping was working from the container but e.g. wget and traceroute etc. were not (a good indication of a firewall "problem").
In my set-up the solution was:
ufw allow in to 172.17.0.0/16 proto tcp port 8084
where 172.17.0.1 is the docker0 IP address and 8084 the port on the host machine.