Skip to main content

rawops.dev

P2

Container Network Failure — Docker Troubleshooting Guide

Troubleshoot Docker container networking failures. Covers DNS resolution, inter-container communication, network inspection, and firewall rules.

15 min7 steps
Progress: 0/7 steps
0%

Verify which networks the container is attached to.

docker inspect CONTAINER_NAME | jq '.[0].NetworkSettings.Networks'
Expected: Shows network name, IP address, and gateway. Container should be on the expected network.

Verify the container can resolve hostnames.

docker exec CONTAINER_NAME nslookup google.com || docker exec CONTAINER_NAME cat /etc/resolv.conf
Expected: DNS should resolve. If it fails, check /etc/resolv.conf for correct nameserver entries.

Check if the container can reach the internet.

docker exec CONTAINER_NAME ping -c 3 8.8.8.8 || docker exec CONTAINER_NAME wget -q -O- http://httpbin.org/ip
Expected: Successful ping or HTTP response. If ping fails but DNS works, it's a routing/firewall issue.

Verify containers on the same network can reach each other.

docker exec CONTAINER_A ping -c 3 CONTAINER_B_NAME
Expected: Containers on the same Docker network should resolve each other by container name.
Containers must be on the same Docker network to communicate by name. Default bridge network doesn't support name resolution.

List networks and inspect the relevant one.

docker network ls && docker network inspect NETWORK_NAME | jq '.[0] | {Name, Driver, Containers: [.Containers[].Name]}'
Expected: Both containers should appear in the same network's container list.

Verify iptables/ufw isn't blocking Docker traffic.

iptables -L DOCKER -n 2>/dev/null | head -10 && iptables -L DOCKER-USER -n 2>/dev/null | head -10
Expected: DOCKER chain should have ACCEPT rules. DOCKER-USER chain should not have DROP rules for your traffic.

If all else fails, recreate the network.

docker compose down && docker network prune -f && docker compose up -d
Expected: All services restarted on fresh networks. Verify connectivity with 'docker exec CONTAINER ping TARGET'.
This causes downtime for all services in the compose file.