← Back to all fixes
Container cannot reach host or other containers
The Issue
App inside container tries to connect to `localhost:5432` (postgres) but gets connection refused.
Root Cause
Inside a container, `localhost` refers to the container itself, not the host machine. Sibling containers are also not reachable via `localhost`.
How to Fix
For host services on Linux: use `172.17.0.1` (default docker bridge gateway) or `--network host`For sibling containers: use Docker Compose and reference by service name, e.g. `postgres:5432`Check which network the container is on: `docker inspect <container> | grep NetworkMode`Use `docker network ls` and `docker network inspect bridge` to see connected containers and their IPs