Consider I have docker-subdomain.mydomain.com
pointing to a website in a Docker container, and host-subdomain.mydomain.com
pointing to a website in the Host itself. Both these websites are in the same Host and IP address.
When the PHP code of the docker-subdomain.mydomain.com
inside Docker makes a curl
call to host-subdomain.mydomain.com
, and that host-subdomain.mydomain.com
logs the IP address of the caller, it appears to be an IP address starting with "172.", which means it's the private IP address of the docker container.
I'm wondering how is the private IP address used, if the DNS of host-subdomain.mydomain.com
is the public IP, so I'd think it would use the external interface to connect? (like it happens when a PHP script executes curl
in the host itself, outside Docker)
How does Docker know that host-subdomain.mydomain.com
points to the same host?
--
Note: I'm not asking how to bypass/change this behavior - I'm just curious, as it's doing exactly what I wanted it to do, but I don't understand why.