Docker Networking Deep Dive¶
Proper networking is key for production containers.
Network Types¶
docker network ls
bridge — default, isolated¶
host — shares the host network¶
overlay — multi-host (Swarm)¶
macvlan — custom MAC address¶
Custom Bridge¶
docker network create mynet docker run -d –name web –network mynet nginx docker run -d –name api –network mynet node-api
curl http://api:3000 from the web container¶
Compose¶
services: web: networks: [frontend] api: networks: [frontend, backend] db: networks: [backend] networks: frontend: backend: internal: true
Debug¶
docker network inspect mynet docker exec web nslookup api
Networking is Key¶
Custom bridge, separate networks, DNS names instead of IPs.