0

I have an API running on my host machine on port 8000. Meanwhile, I have a docker compose cluster with one container that's supposed to connect said API. To get the url for the request, I use "host.docker.internal:8000" on my windows machine and it works wonderfully. However, I have a linux deployment server and in there, "host.docker.internal" doesn't resolve to anything, causing a connection error to the API. I saw on another post on stackoverflow, that you solve this on linux by adding the following on your docker-compose.yaml

services:
  service_name:
    extra_hosts:
      - host.docker.internal:host-gateway

This added the docker0 IP to /etc/hosts, but when I try to do a GET request, the resulting message is:

Failed to connect to host.docker.internal port 8000: Connection refused

I'm really confused right now. I don't know if this is a firewall issue, a docker issue, a docker compose issue, a docker on linux issue. Please help...

Eddysanoli
  • 169
  • 1
  • 2
  • 10
  • 1
    Make sure your API binds to 0.0.0.0 and not to localhost. If it binds to localhost, it won't accept connections from containers. – Hans Kilian Apr 13 '22 at 21:31
  • This worked perfectly! Thank you. I just changed the API binding and everything started working. – Eddysanoli Apr 14 '22 at 02:19

0 Answers0