Im encountering an issue with docker which I believe is due to a gap in my knowledge about docker networking.
I have a docker image running nginx and php. The necessary ports are exposed. Here is a simplified command I have been using to run the image.
docker run --name php-app -p 80:80 php-app
The issue is that for installation setup, the php application curls to itself using the host machines public IP.
As an example,
curl http://105.15.25.120/phpsetup.php?setup
This IP seems to be unreachable from inside the container, as curl times out
curl -vvv 105.15.25.120
About to connect() to 105.15.25.120 port 80 (#0)
Trying 105.15.25.120...
Connection timed out
Failed connect to 105.15.25.120:80; Connection timed out
Closing connection 0
curl: (7) Failed connect to 105.15.25.120:80; Connection timed out
I can successfully curl to other IP's from inside the container, just not the host's.
Using curl from the host machine works fine, and does not result in any strange behaviour.
For simplicity and testing, I have reproduced the behaviour with the official nginx image, to help conclude that it's not an issue with my own image.
docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -p 80:80
From my research, it seems to be a routing issue? Not sure.
the container should not curl the host. it should curl itself, as it is hosting the content you wish to curl.
curl http://127.0.0.1/phpsetup.php?setup