Troubleshoot Docker Compose Networking and DNS
Before you begin
- Applies to:Docker Engine on Linux with Compose v2 and bridge networks.
- Where to start:Open a terminal in the deployed Compose project on the Docker host. Use the same Docker context and project as the deployment.
- What you need:Identify the source and destination services. The examples use web and api. The source needs getent and curl, and the destination needs ss. Use approved diagnostic tooling if these are missing. Keep the same shell for commands that share variables.
Guide tools
Use this guide when a service name does not resolve or a container cannot connect to another container. Check from the failing container because host DNS and host port checks exercise a different path.
Troubleshooting Steps
Check the project and shared network
Docker hostRun in the deployed project directory. Confirm the containers are running and inspect the actual memberships. Replace the example names with those from compose ps. The containers need a common network for the direct service-name path in this guide.
docker compose ps --alldocker compose config --servicesdocker inspect --type container --format '{{json .NetworkSettings.Networks}}' example-web-1 example-api-1Resolve the service name and test HTTP
Source containerRun each command from the Docker host. Compose exec runs the probe inside web. The first command should return the service address. The second should return the expected status for the API health endpoint. A name failure points to network membership or service aliases. A refusal after resolution points toward the API listener or port.
What you should see · The source container resolves the API service name and the health endpoint returns its expected HTTP status.
If you see something else · If the name does not resolve, return to Step 1 and check the shared network and service name. If it resolves but the connection fails, go to Step 3 for the listener and container port. If HTTP responds with an error, inspect the API logs and health endpoint.
docker compose exec -T web getent hosts apidocker compose exec -T web curl --connect-timeout 3 --max-time 8 --fail --show-error http://api:8080/healthCheck the service listener and host mapping
Destination containerFor traffic from another container, confirm the application listens on a reachable container interface at 8080. An application bound to 127.0.0.1 inside the API container is reachable only from that container. The second command checks for a published host port. No published mapping is normal for an internal API.
docker compose exec -T api ss -lntdocker compose port api 8080Restore the intended path and verify
ResolutionCorrect the identified service name, shared network, or application bind setting in version-controlled configuration. Use docker compose config —quiet to validate the edit. Apply it with the project’s deployment process, then repeat the source-container checks. For persistent failure restore the previous configuration and compare both containers’ memberships again.
docker compose config --quietdocker compose exec -T web getent hosts apidocker compose exec -T web curl --connect-timeout 3 --max-time 8 --fail --show-error http://api:8080/healthReferences
Your feedback keeps these production procedures accurate and battle-tested.