Docker network troubleshooting and debugging techniques
docker network inspect, docker exec ping, nslookup inside container, netstat inside container, connectivity testing, common network errors
Diagnosing Container Network Problems
Networking issues are among the most common sources of Docker confusion. Here is a systematic process to diagnose them.
Step 1 — Check Network Membership
docker network inspect app-network
Look at the Containers section. If your container isn't listed, it's not on this network — that's why it can't reach other containers on it.
Step 2 — Test DNS and Connectivity from Inside a Container
# Get a shell in the running container
docker exec -it my-api sh
# Check if the target resolves
nslookup postgres
# Check if the port is reachable
wget -qO- http://postgres:5432 || echo "Port not responding"
If nslookup fails, the containers are not on the same network. If DNS resolves but the port fails, the target container's process may have crashed or is listening on the wrong interface.
Step 3 — Run a Diagnostic Container
docker run -it --rm \
--network app-network \
alpine sh
Alpine includes ping, nslookup, and wget. This lets you test connectivity between networks without modifying your application containers. The --rm flag ensures it self-destructs when you exit.
