Skip to main content
⚡ OpenDevDocs
Docker
devopsdockerGuideIntermediate

Docker Networks & Service Discovery

Complete guide to Docker networking drivers (bridge, host, overlay, macvlan, none), custom user-defined networks, and DNS-based container service discovery.

Verified: 2026-09-30
Tested on:docker 27.x
Platforms:
linuxmacoswindows
#docker#networks#dns#networking#devops

Docker networking enables containers to communicate with each other and with external networks securely.


Network Drivers

DriverDescriptionCommon Use Case
bridgePrivate virtual Ethernet bridge with internal NAT (Default)Standalone containers on single host
hostContainer shares host network namespace directlyMaximum throughput; removes network isolation
overlayMulti-host network for Swarm / Kubernetes clustersDistributed multi-node setups
macvlanAssigns container a real physical MAC address on host LANLegacy networking apps needing physical IPs
noneDisables all networking interfaces except loopbackAir-gapped batch compute jobs

User-Defined Bridge Networks & Automatic DNS

The default bridge network does not support automatic container name resolution (only IP addresses). Custom user-defined bridge networks enable built-in DNS service discovery:

# 1. Create a custom network
docker network create my-app-net

# 2. Run database container on the network
docker run -d --name postgres-db --network my-app-net \
  -e POSTGRES_PASSWORD=secret \
  postgres:16-alpine

# 3. Run application container on the same network
docker run -d --name web-api --network my-app-net \
  -e DATABASE_URL="postgresql://postgres:secret@postgres-db:5432/postgres" \
  -p 3000:3000 \
  my-api-image

Inside web-api, resolving the hostname postgres-db automatically translates to the internal container IP address!


Network Management Commands

# List all networks
docker network ls

# Inspect network subnet and attached containers
docker network inspect my-app-net

# Connect an already running container to another network
docker network connect my-app-net container-id

# Disconnect container from network
docker network disconnect my-app-net container-id

# Delete unused networks
docker network prune

On this page