So I have created a network like:
IPV4 Subnet 172.20.0.0/16 172.20.1.1
I have a container at 172.20.1.4 that needs to reach the host IP which I know is always 172.17.0.1 in Docker.
The issue is that if I do a ping, the container sees the IP but if I do a
curl -X POST I have a
couldn't connect to the server error
How can I reach the host?
ping works but
curl not, then there may be no service listening on the targeted port of the IP.
there is, as I can curl from host to that specific ip:port and it answers correctly
Since you are using the same curl command with the same IP address on the host and if ping works, all that remains is a firewall that blocks UDP/TCP packages while ping is ICMP which could be blocked too but not always is. Locally it wouldn’t matter if you can ping a private IP address but you sometimes you don’t want a container to access anything on the host. That is not a default setting at least not in Docker so something else must have blocked the request. Here is an article (and video) in which I share some thoughts about Docker networks and how you can debug it.