Introduction Docker containers that cannot connect to their custom networks are isolated from other containers and external services. This breaks microservice communication, database connectivity, and service discovery.

Symptoms - `docker network connect` fails with error - Container cannot reach other containers by name - Error: "network <name> not found" or "address already in use" - DNS resolution fails inside container (nslookup returns NXDOMAIN) - Container gets stuck during startup waiting for dependencies

Common Causes - Custom network was deleted or not created - IP address conflict in the network's subnet - Docker embedded DNS server not functioning - Container started before network was created - iptables rules blocking container network traffic

Step-by-Step Fix 1. **Check available networks**: ```bash docker network ls docker network inspect <network-name> ```

  1. 1.Recreate the network if missing:
  2. 2.```bash
  3. 3.docker network create --driver bridge \
  4. 4.--subnet=172.20.0.0/16 \
  5. 5.--gateway=172.20.0.1 \
  6. 6.my-network
  7. 7.`
  8. 8.Connect container to network:
  9. 9.```bash
  10. 10.docker network connect my-network <container-name>
  11. 11.`
  12. 12.Test DNS resolution inside container:
  13. 13.```bash
  14. 14.docker exec <container-name> nslookup other-container
  15. 15.docker exec <container-name> ping other-container
  16. 16.`
  17. 17.Restart Docker networking if DNS is broken:
  18. 18.```bash
  19. 19.sudo systemctl restart docker
  20. 20.# Or flush iptables rules that may block Docker traffic
  21. 21.sudo iptables -F DOCKER-USER
  22. 22.`

Prevention - Use docker-compose to manage networks and containers together - Define explicit subnets in compose files - Use depends_on to ensure networks exist before containers start - Monitor Docker daemon logs for network errors - Use overlay networks for multi-host setups