Docker · infra · fg-0256

Container cannot reach a service on the host through localhost, and host.docker.internal does not resolve on Linux

connect ECONNREFUSED 127.0.0.1:5432 from inside the container

Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100

Cause

Inside a container, localhost is the container itself. Docker Desktop resolves host.docker.internal on its own, but Docker Engine on Linux only does when you map the name to the special host-gateway value.

Fix

Map host.docker.internal to host-gateway and make the host service listen on an address the bridge can reach. Between Compose services, connect by service name instead.

Apply

services:
  app:
    extra_hosts:
      - "host.docker.internal:host-gateway"
# docker run: --add-host host.docker.internal=host-gateway

Affects: Docker Engine on Linux, as of October 2026; Docker Desktop resolves the name by default

Sources

Have your agent know this before it fails

claude mcp add --transport http footgun https://getfootgun.com/api/mcp