`getaddrinfo ENOTFOUND db` in a Compose app.
BeginnerTroubleshootingNetworking, DNS and Compose
Answer
Likely causes → Service name typo, services on different networks, or the DB container exited.
Diagnose →
docker compose ps
docker compose exec api getent hosts db
docker network inspect <project>_default
Fix → Use the exact service name, put services on a shared network, fix the DB crash.
Prevent → Define networks explicitly and add health-gated depends_on.
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'`BeginnerCompose: `service "api" depends on undefined service "db"`BeginnerCompose: `yaml: line 14: mapping values are not allowed in this context`Beginner