Docker networking allows containers to talk to:
- Each other
- The host
- The outside world
Understanding this is key if you’re running:
- Microservices
- Reverse proxies (like Nginx)
- Multi-container setups
๐ง Default Network Types
1. Bridge (Default)
docker network ls
- Containers communicate via IP
- Isolated from host network
2. Host Network
docker run --network host nginx
- No isolation
- Uses host ports directly
3. None
docker run --network none nginx
No network access
๐ฅ Custom Bridge Network (BEST PRACTICE)
docker network create my_network
Run containers inside:
docker run -d --name app --network my_network nginx
docker run -d --name db --network my_network mysql
๐ Now they can communicate using:
ping db
๐ Real Example (Reverse Proxy Setup)
- Nginx โ frontend
- App โ backend
- DB โ database
All inside one network:
docker network create prod_net
โ ๏ธ Common Mistakes
- โ Using default bridge for production
- โ Hardcoding container IPs
- โ Not isolating services
๐งฉ Best Practices
- Use custom networks
- Use container names as DNS
- Keep services isolated
- Combine with firewall rules
๐ Conclusion
Docker networking is powerful โ and once you understand it, building scalable systems becomes much easier.