Docker Networking
Estimated reading: 4 minutes 62 views

๐Ÿณ Docker Network Troubleshooting โ€“ Step-by-Step Guide with Examples & FAQs


๐Ÿงฒ Introduction โ€“ Why Learn Docker Network Troubleshooting?

When working with Docker, network issues can silently break your application. Whether it’s containers failing to communicate, port bindings not working, or DNS resolution failing, Docker networking problems are frustratingโ€”but fixable.

This step-by-step guide simplifies Docker network troubleshooting with real-world examples, tips, and diagnostic commands for beginners and pros alike.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • How Docker networking works
  • How to diagnose broken container connections
  • How to fix port mapping and DNS issues
  • How to use custom networks effectively
  • Real-world commands and FAQs for fast fixes

๐Ÿ“ก What is Docker Networking?

Docker networking allows communication between:

  • Containers
  • The host machine
  • External networks (like the internet)

๐Ÿš€ Common Docker Network Types

Network TypeDescription
bridgeDefault for standalone containers
hostUses host’s network stack directly
noneCompletely disables networking
overlayUsed for multi-node Swarm setups
macvlanAssigns a MAC address like a physical device

๐Ÿ” Common Docker Networking Problems

Here are typical issues developers face:

  • โŒ One container cannot access another
  • โŒ Exposed port not accessible from host
  • โŒ DNS fails inside container (ping: unknown host)
  • โŒ Port is not mapped or incorrectly published
  • โŒ Firewall or SELinux blocking traffic

๐Ÿ› ๏ธ Step-by-Step Docker Network Troubleshooting


โœ… Step 1: View Available Networks

docker network ls

๐Ÿ“Œ Example Output:

NETWORK ID     NAME      DRIVER    SCOPE
f3b2c1328a0d   bridge    bridge    local
ae33cb2478d1   host      host      local
e9a1d847eec7   none      null      local

โœ… Step 2: Inspect a Network

docker network inspect bridge

๐Ÿง  This shows which containers are connected and their IPs.


โœ… Step 3: Check Containerโ€™s Network Info

docker inspect my_container

๐Ÿ”Ž Look for the NetworkSettings block:

"IPAddress": "172.17.0.2",
"Gateway": "172.17.0.1",

โœ… Step 4: Test Container-to-Container Communication

  • Using ping:
docker exec -it web ping app
  • Using curl:
docker exec -it web curl http://app:3000

๐Ÿ“Œ Useful when both containers are on the same user-defined network.


โœ… Step 5: Create a User-defined Network

docker network create my-network

Attach containers:

docker run -d --name web --network my-network nginx
docker run -d --name app --network my-network node-app

Test communication:

docker exec -it web curl http://app:3000

โœ… Worksโ€”because Dockerโ€™s internal DNS resolves names in user-defined networks.


โœ… Step 6: Check Port Bindings

docker ps

๐Ÿ“Œ Output:

CONTAINER ID   IMAGE   PORTS
3df2a1b43e54   nginx   0.0.0.0:8080->80/tcp

If PORTS column is empty or wrong:

docker run -d -p 8080:80 nginx

Then:

curl http://localhost:8080

โœ… Step 7: Test DNS Resolution Inside Container

Install DNS tools:

docker exec -it web apt update && apt install -y dnsutils
docker exec -it web nslookup app

โœ… If successful:

Name:   app
Address: 172.18.0.3

If it fails:

  • Check if both containers are on the same network
  • Use docker network inspect to verify

โœ… Step 8: Monitor Traffic with tcpdump

To monitor Docker traffic:

sudo tcpdump -i docker0

๐Ÿ“Œ Example: Trace packets between Nginx and Node.js on port 3000.


โœ… Step 9: Check for Firewall or SELinux

  • Flush iptables rules temporarily:
sudo iptables -F
  • Temporarily disable SELinux:
sudo setenforce 0

โš ๏ธ Donโ€™t forget to re-enable after testing.


๐Ÿ“Œ Summary โ€“ Recap & Next Steps

Troubleshooting Docker networking becomes easy once you know what to look for. From checking container connectivity to fixing DNS and firewall rules, each step leads to faster resolution and better infrastructure practices.

๐Ÿ” Key Takeaways:

  • Use user-defined bridge networks for DNS-based resolution.
  • Always check docker ps for port bindings.
  • Inspect containers and networks with docker inspect and network inspect.
  • Use curl, ping, nslookup, and tcpdump to validate connectivity.
  • Keep an eye on firewall, iptables, and SELinux settings.

โš™๏ธ Real-World Tip: Docker Compose can simplify complex networking setups by defining networks and services declaratively.


โ“ FAQs โ€“ Docker Network Troubleshooting


โ“ Why canโ€™t my containers communicate?

โœ… Theyโ€™re probably on different networks. Use a user-defined network:

docker network create my-net
docker network connect my-net container1
docker network connect my-net container2

โ“ How do I connect a running container to a new network?

docker network connect my-network my-container

To remove:

docker network disconnect bridge my-container

โ“ What’s the difference between bridge and host networks?

NetworkDescription
bridgeDefault; isolated unless port mapped
hostNo isolation; shares hostโ€™s IP stack

โ“ Why is DNS failing inside the container?

โœ… Internal DNS resolution works only in user-defined networks. Use:

docker network create my-net

Then launch all related containers in that network.


โ“ How to remove unused Docker networks?

docker network prune

๐Ÿงผ This safely deletes all unused networks.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Docker Network Troubleshooting

Or Copy Link

CONTENTS
Scroll to Top