0

I'm running a web service on http://localhost:8000, where I want to connect from a docker container. So basically inside the docker container I've tried

  • requests.get("http//:localhost:8000)
  • requests.get("http//:host.docker.internal:8000)
  • requests.get("http//:0.0.0.0:8000)

but all these give an

equivalent error: **requests.exceptions.ConnectionError:
HTTPConnectionPool(host='host.docker.internal', port=8000): Max
retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f95892fdbb0>: Failed to establish a new connection: [Errno -2]
Name or service not known'))**
LinFelix
  • 1,026
  • 1
  • 13
  • 23
Joel
  • 1
  • 1
  • Im running docker via docker-compose up and this how my docker-compose.yml looks like https://imgur.com/a/D51rASd – Joel Apr 07 '22 at 12:07
  • Which docker version are you running? Also can you share the Dockerfile for the `test` container? The correct way to get to the host from a docker container is to point to `host.docker.internal` – Matteo Zanoni Apr 07 '22 at 12:12
  • `localhost` from the container is the container, not your host machine. Put your WS in a docker container and put the 2 in a Docker network, or use host networking. – AymDev Apr 07 '22 at 12:16
  • Docker version 20.10.14, build a224086 dockerfile: https://imgur.com/a/lzPxiXC – Joel Apr 07 '22 at 12:16
  • @AymDev Ive added the "extra_hosts: - "host.docker.internal:host-gateway"" to the docker-compose.yml, but it doesnt have any affect. – Joel Apr 07 '22 at 12:19
  • i solved the issue by replacing "host-gateway" by my machines local ip in the "host.docker.internal:host-gateway" – Joel Apr 12 '22 at 06:38

0 Answers0