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…
2
Answers
I had a similar problem and got it working by making sure that my tunnel accepted connections from everywhere.
Before:
After:
Credit to @Hans Kilian:
extra_hosts
to docker-compose filehost.docker.internal
instead oflocalhost
0.0.0.0
instead oflocalhost