Skip to content

Docker networks — bridge, host, and user-defined

A practical map of Docker network modes — what bridge, host, none, and user-defined bridges actually do, when to use each, and the pitfalls that bite in production.

Docker ships with four built-in network drivers — bridge, host, none, and overlay — plus the ability to create user-defined networks with any of those drivers. The choice you make at docker run --network time determines IP allocation, DNS resolution, port publication semantics, and isolation between containers. Picking the wrong one quietly causes the bugs people blame on Docker.

How to verify

Survey what networks exist on a host and which containers are attached to each:

docker network ls
docker network inspect bridge | jq '.[].Containers'
docker network inspect <network-name>
ip -br addr show | grep -E "docker0|br-"
sudo iptables -t nat -L DOCKER -n | head -20

The default bridge (docker0 on the host) is shared by every container started without --network. User-defined bridges show up as br-<hash> interfaces. docker network inspect reveals the subnet, gateway, and connected containers.

What’s happening

Bridge is the default for any container on a single host. A virtual L2 bridge (docker0) lives on the host; each container gets a veth pair, one end inside the container’s network namespace, one end attached to the bridge. The default bridge has no automatic DNS resolution between containers — you can reach them by IP, but not by name. That’s the single biggest reason to never use the default bridge in production.

User-defined bridge is the same driver with a docker network create wrapper. The difference: containers on a user-defined bridge can resolve each other by container name via Docker’s embedded DNS. This is the right default for multi-container apps on one host.

Host mode shares the host’s network namespace — the container has no isolation, listens on the host’s interfaces directly, and EXPOSE/-p flags do nothing. Faster (no NAT, no veth pair), useful for high-throughput services where the latency tax of bridge mode matters. Dangerous because port collisions become host-wide, and a container compromise gives the attacker the host’s network position.

None disables networking entirely. The container has only its loopback. Use for jobs that just process local data and need no external connectivity.

Overlay spans multiple hosts via VXLAN, used by Swarm and (without Swarm) by manually-created overlay networks. See Docker overlay networks in Swarm for the operational details.

The procedure

  1. Don’t use the default bridge. Create a user-defined network for every project:
docker network create --driver bridge \
  --subnet 172.30.0.0/24 \
  --gateway 172.30.0.1 \
  --opt com.docker.network.bridge.name=br-app \
  app-net

The --subnet lets you avoid clashes with VPN ranges or other docker networks. The bridge.name opt gives the host-side interface a readable name (br-app instead of br-7c3f...).

  1. Attach containers to the user-defined network. DNS now works by container name:
docker run -d --name api --network app-net myapi:latest
docker run -d --name db  --network app-net postgres:16

# From inside api:
docker exec api sh -c "nslookup db; curl -s http://db:5432"
# 'db' resolves to the postgres container's IP automatically
  1. Publish ports only where needed. Most internal traffic stays on the bridge; only the edge-facing service exposes a port:
docker run -d --name web --network app-net \
  --publish 127.0.0.1:443:8443 \
  mynginx:latest

Binding to 127.0.0.1 means only the host (and whatever proxies the host runs) can reach it. Binding to 0.0.0.0 or omitting the IP exposes the container to every interface, including public ones — frequently not what you want.

  1. For high-performance services, host mode skips NAT. Pick this knowingly:
docker run -d --network host \
  --name myproxy \
  --cap-add NET_BIND_SERVICE \
  mynginx:latest

With --network host the container’s port 80 is the host’s port 80 directly. Useful for a reverse proxy in front of other host-network or bridge containers; bad for anything that needs to coexist on a port with other services.

  1. Inspect cross-container connectivity from inside a container:
docker run --rm --network app-net nicolaka/netshoot \
  sh -c "ping -c 2 db && dig +short db && traceroute db"

nicolaka/netshoot is the standard “network debug container” — it has dig, tcpdump, nmap, curl, ip, ss, and most of the network tools that minimal images deliberately omit.

  1. Disconnect/reconnect a running container to change its network attachment:
docker network disconnect bridge mycontainer
docker network connect app-net mycontainer

Useful when refactoring or when a container needs temporary access to a sister network.

Common pitfalls

  • Leaving the default bridge in place and wondering why containers can ping each other by IP but not by name — that’s the default bridge’s no-DNS behavior. Switch to a user-defined network.
  • Using --network host with a container that also has -p 8080:8080 — the -p flag is silently ignored under host networking, but engineers reading the command line don’t realize the port mapping is dead.
  • Two compose projects on the same host both using the default subnet (172.17.0.0/16 or similar) and clashing with each other or with a VPN range. Always set explicit subnets for user-defined networks.
  • Mounting --network host for “convenience” and giving a compromised container the host’s network identity, including its DNS view of internal services.
  • Forgetting that EXPOSE in a Dockerfile is documentation only — it doesn’t publish a port. Only -p/--publish actually opens a host port.

We bake user-defined networks, internal-only attachments, and explicit subnet allocations into every Compose file we ship, as part of the managed operations base. The default bridge stays unused.