0

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.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
DaiShogun
  • 20
  • 5
  • did you use `localhost` as the hostname for the flask application? – Noam Yizraeli Sep 06 '21 at 06:39
  • Where is the external API running (in another container on the same host, on the same host not in the same container, on another host in the same network, out on the public Internet)? Do you have any special DNS configuration for your container, or for the host system? What URL are you trying to connect to? – David Maze Sep 06 '21 at 11:04
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 10 '21 at 11:52

1 Answers1

1

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>
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74