There is a very Docker Compose moment: Postgres is running, the API is running, the logs look reasonable, and the API still says it can't connect to localhost:5432 .
You check docker compose ps . Postgres is Up . You check the docker-compose.yml . The port is there. You stare at the screen with that specific mix of suspicion and tiredness that only appears when a tool is technically telling the truth in the least helpful way possible.
Is Postgres down? No. Is the port wrong? Maybe, but probably not. Is localhost a trap with good branding? Exactly.
In Docker Compose, each container lives in its own little network world. Once you understand that, the rest stops feeling like dark magic with YAML.
Compose's default network
When you run docker compose up , Compose automatically creates a network for the project.…