Networking — Cheat Sheet
Docker · 1 topics. Download the PDF or the Instagram carousel and share it.
Cheat Sheet · AiCanCode.org
Networking
Docker1 topicsQuick revision reference
1
Docker Networking
Docker provides isolated virtual networks for containers. Understanding bridge, host, and overlay networks — and how containers discover each other by name — is essential for multi-container apps.
- ✓User-defined bridge networks provide automatic DNS: containers resolve each other by name.
- ✓Default bridge network only allows IP-based communication.
- ✓Port mapping (-p host:container) is required to expose container services externally.
- ✓Host network mode removes network isolation — container uses host's network stack directly.
- ✓Overlay networks connect containers across multiple hosts (Swarm/Kubernetes).
- ✓Docker Compose automatically creates a user-defined network for all services in the file.
bash — user-defined bridge network
# Default bridge: containers communicate by IP only (fragile) docker network ls # NETWORK ID NAME DRIVER SCOPE # 3b8c9f1a2d bridge bridge local ↠default # 8e4f7c1b3d host host local # 9a2b5e0c8f none null local # ✅ Create user-defined bridge (containers get DNS by name) docker network create my-app-net # Run containers on the same network docker run -d --name postgres --network my-app-net postgres:16 docker run -d --name backend --network my-app-net \ -e DATABASE_URL=postgres://postgres:5432/mydb \ # resolve 'postgres' by name! my-backend:latest # Test DNS resolution inside a container docker exec -it backend sh # Inside: ping postgres → resolves to postgres container IP
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/docker