When two containers cannot reach each other, I first want to know which network each one is on. The network itself can tell me.
docker network ls
docker network inspect bridge
The output is JSON with the driver, the subnet and gateway under IPAM, and a Containers section that lists the attached containers with their IP and MAC addresses. If a container is not listed on the network where you expected it, you found your problem.
The JSON is long, so --format with a Go template extracts what you need:
docker network inspect bridge --format '{{range .Containers}}{{.Name}} {{.IPv4Address}}{{println}}{{end}}'
That prints one line per container with its name and address. For a Compose project, the network name is usually the project name followed by _default, which docker network ls shows.
The caveat is that the list describes the current situation. Containers that are stopped usually do not appear in it, so an empty list does not mean nothing was ever attached. Also, containers on the default bridge network cannot find each other by name. Only user-defined networks provide that, so check which kind of network you are looking at before debugging DNS.
Further reading: docker network inspect