Networking Basics
Docker networks let containers talk to each other and to the outside world through different network drivers.
Syntax
docker network lsContainers often need to communicate — a web app talking to a database, for example. Docker's networking makes this possible and controllable.
Network drivers
- bridge — the default; containers on the same bridge network can reach each other. Best for single-host setups.
- host — the container shares the host's network directly, with no isolation.
- none — no networking at all.
- overlay — connects containers across multiple hosts (used with Swarm).
Listing networks
Run docker network ls to see the networks Docker has created.
Example
# List existing networks
docker network ls
# NETWORK ID NAME DRIVER
# ... bridge bridge
# ... host host
# ... none null
# Inspect the default bridge network
docker network inspect bridgeWhen to use it
- A developer connects a web container and a Redis container through a bridge network so they can communicate without exposing Redis to the host.
- An ops engineer uses a host network for a monitoring agent container so it can inspect host-level network interfaces directly.
- A team uses the none network driver to run a cryptographic computation container with no network access for security isolation.
More examples
List available Docker networks
Shows all networks on the Docker host, including the default bridge, host, and none networks.
docker network lsInspect a network
Shows details of the default bridge network including its subnet, gateway, and any connected containers.
docker network inspect bridgeConnect container to host network
Runs a container sharing the host's network stack so it can scrape host network interfaces without port mapping.
docker run -d \
--network host \
--name monitor \
prom/node-exporter
Discussion