Docker Networking

Docker containers communicate with each other and the outside world using built-in virtual network drivers.

1. Network Drivers Overview

DriverDescriptionUse Case
bridge (Default)Isolated software network bridge on single hostDefault for standalone application containers
hostRemoves network isolation between container and hostHigh-performance standalone networking
overlayConnects multiple Docker daemons across cluster hostsDocker Swarm & Kubernetes clusters
noneDisables all networking capabilities for containerIsolated 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 →