Container-to-container requests fail intermittently by name after a container restarts.
AdvancedTroubleshootingNetworking, DNS and Compose
Answer
Likely causes → Client (nginx, JVM) cached the old IP; DNS TTL and resolver caches ignore the new address.
Diagnose → docker exec web getent hosts api vs the IP in nginx upstream; docker network inspect.
Fix → In nginx use resolver 127.0.0.11 valid=10s; with variable in proxy_pass; JVM networkaddress.cache.ttl=10; or reload nginx.
Prevent → Configure resolver behaviour when using dynamic backends.
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