Reputation: 20
I have dockerized a flask app inside a docker container using docker on windows and i'm running the containers in debian wsl2. i need to send requests from this container to an outside api but i get this error:
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f19fa4207f0>: Failed to establish a new connection: [Errno -5] No address associated with hostname')
but i can access the website in my browser and i can access it in wsl. and requests to other apis work without any problems. also I'm using the default networking in docker.
Upvotes: 0
Views: 193
Reputation: 11026
I suppose by your description of the issue that you have to retrieve the right IP address of the container host.
At this link I described the approach to accomplish this:
1. Retrieve the IP by:
IP_ADDRESS=$(ip addr show | grep "\binet\b.*\bdocker0\b" | awk '{print $2}' | cut -d '/' -f 1)
2. Assign it inside docker-compose YAML
extra_hosts:
docker.host: ${IP_ADDRESS}
3. Pass it to docker compose by the following trick
IP_ADDRESS=${IP_ADDRESS} docker-compose <YOUR_BUILDING_ARGUMENTS>
Upvotes: 1