Docker Compose Networking & Service Discovery Debug Prompt
Troubleshoot Compose services that cannot reach each other, fail DNS resolution, hit port conflicts, or start before dependencies are ready, and produce a corrected compose file.
- Target user
- DevOps engineers and full-stack developers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior engineer who debugs Docker Compose networking and service-discovery problems. I will provide: - My `docker-compose.yml` (or compose.yaml) full contents - The exact error (connection refused, name resolution failed, port already allocated, timeout) - Which service is trying to reach which, and how (hostname:port, env-driven URL) - Output of `docker compose ps` and any relevant `docker compose logs` Your job: 1. **Map the topology** — list services, the networks they join, and which containers can resolve which names; confirm services that must talk are on the same user-defined network. 2. **Fix service-to-service addressing** — services should reach each other by service name and the container's internal port, not `localhost`, not the published host port; correct any URLs using the wrong host or the mapped port. 3. **Resolve port conflicts** — separate published ports (`HOST:CONTAINER`) from internal ports; fix `already allocated` errors and clarify when publishing is even needed. 4. **Handle startup ordering** — explain why `depends_on` alone does not wait for readiness, and add a `condition: service_healthy` with a healthcheck or an app-level retry. 5. **Check DNS & aliases** — verify the embedded DNS, network aliases, and that the default bridge vs a custom network is being used (default bridge has no name resolution). 6. **Give probes** — `docker compose exec <svc> getent hosts <other>`, `nc -zv`, `curl` from inside a container to confirm reachability. Output as: (a) topology map, (b) the specific misconfiguration, (c) corrected compose snippets, (d) in-container verification commands.
Related prompts
-
Crashing Container Exit-Code & Log Debug Prompt
Diagnose why a container exits immediately, restart-loops, or gets OOM-killed by reading its exit code, logs, and inspect output, then produce a ranked fix list.
-
Volume Mount & Permission Troubleshooting Prompt
Fix Docker volume problems: permission-denied on bind mounts, UID/GID mismatch between host and container, data not persisting, or a named volume masking image content.