Access from container to host service fails: `connection refused host.docker.internal` on Linux.
IntermediateTroubleshootingNetworking, DNS and Compose
Answer
Likely causes → Name not defined on Linux by default, or the host service binds only to 127.0.0.1, or a firewall blocks the bridge interface.
Diagnose →
docker run --rm --add-host host.docker.internal:host-gateway busybox getent hosts host.docker.internal
ss -tlnp | grep <port>
Fix → Add extra_hosts, bind the service to 0.0.0.0 or the bridge IP, allow docker0 in the firewall.
Prevent → Prefer running dependencies as containers.
More on Networking, DNS and Compose
`curl: (7) Failed to connect to localhost port 8080: Connection refused` after `docker run -p 8080:80 nginx`.Beginner`Bind for 0.0.0.0:5432 failed: port is already allocated`BeginnerContainers cannot reach the internet: `Temporary failure in name resolution`Advanced`ping` works to IPs but DNS names fail on the default bridge: `ping: bad address 'db'`Beginner`getaddrinfo ENOTFOUND db` in a Compose app.BeginnerCompose: `service "api" depends on undefined service "db"`Beginner