Docker Networking
Docker containers communicate with each other and the outside world using built-in virtual network drivers.
1. Network Drivers Overview
| Driver | Description | Use Case |
|---|---|---|
bridge (Default) | Isolated software network bridge on single host | Default for standalone application containers |
host | Removes network isolation between container and host | High-performance standalone networking |
overlay | Connects multiple Docker daemons across cluster hosts | Docker Swarm & Kubernetes clusters |
none | Disables all networking capabilities for container | Isolated security sandboxes |
2. Custom Bridge Networks & Automatic DNS
Containers attached to custom user-defined bridge networks can automatically discover and communicate with each other using container names as DNS domain names!
# 1. Create a custom network docker network create my-app-network # 2. Run Database container on custom network docker run -d \ --name db-server \ --network my-app-network \ -e POSTGRES_PASSWORD=secret \ postgres:15-alpine # 3. Run Backend API container on SAME network # Notice DB connection host is 'db-server' (DNS resolution works automatically!) docker run -d \ --name backend-api \ --network my-app-network \ -e DB_HOST=db-server \ -p 3000:3000 \ myusername/backend:latest
Next Up
Master Docker Compose Basics: defining multi-container services inside docker-compose.yml.
Next Lesson: Docker Compose Basics →