Docker Network Drivers
| Driver | Description | Use case |
|---|---|---|
bridge | Default; isolated virtual network from the host | Container communication on a single host |
host | Uses the host network directly | When performance is the top priority |
none | Completely disables networking | When full isolation is required |
overlay | Multi-host network | Docker Swarm |
Basic Network Commands
Bash
docker network ls
docker network inspect bridge
docker network create mynet
docker network create \
--driver bridge \
--subnet 172.20.0.0/16 \
--gateway 172.20.0.1 \
mynet
docker network connect mynet container1
docker network disconnect mynet container1Custom Bridge Networks (Recommended)
Bash
docker network create app-net
docker run -d --name db --network app-net postgres:16
docker run -d --name backend --network app-net \
-e DB_HOST=db \
myapp:latestCompose Network Configuration
YAML
services:
nginx:
image: nginx:alpine
ports:
- "80:80"
networks:
- frontend
app:
build: .
networks:
- frontend
- backend
db:
image: postgres:16
networks:
- backend
networks:
frontend:
backend:
internal: truePort Mapping
Bash
docker run -p 8080:80 nginx
docker run -p 127.0.0.1:8080:80 nginx # localhost
docker port container1Debugging
Bash
docker exec -it myapp sh
# nslookup db
# curl http://db:5432
docker inspect --format '{{.NetworkSettings.IPAddress}}' mycontainerEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Docker documentation ↗
Questions & answers
Ask a question about this guide. We'll review and reply.