Docker in Docker: send GET request to newly created container is failing

Using Python’s SDK Docker package, I started a container.

I get its IP address using container_address = f"http://{container.attrs['NetworkSettings']['IPAddress']}:80/"

Using the requests package, I tried to get that endpoint.

The following error appears:

HTTPConnectionPool(host='172.18.0.2', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f7845af3010>, 'Connection to 172.18.0.2 timed out. (connect timeout=None)'))

The same script works fine locally, meaning that using Docker’s Python SDK I can run a container and do a GET request.

Any ideas why it’s failing in the pipeline?