I'm trying to set up a local development environment with multiple services and started following a docker compose tutorial. I got the basic example running, but when I tried to adapt it for my own project with a database and a cache, the networking just wouldn't work. How do you debug when containers can't talk to each other?
That sounds frustrating. First check that both services share the same docker compose network. You can inspect the network in the compose file and then open a shell in one container to ping the other by its service name. If the ping fails the problem is network related and not code. Are you using the default network or a custom one
Make sure the service hostnames are the service names you defined not localhost inside the container. When you connect from one container to another use the service name as the host name rather than localhost or 127.0.0.1
Check how the network is defined in the yaml. In compose the default network is a bridge unless you specify otherwise, and external networks can cause containers to live in separate islands
Remember that depends on only controls startup order not readiness. Add health checks for both services and rely on their healthy status to bring up dependent services
Use logs and a simple connectivity test to trace the path. From inside a container try to curl the other service and see where the request stops or if it reaches the port at all
If you want share a snippet of your docker compose file and the exact errors and I will offer targeted fixes Want to share the snippet?