Networking Basics

Docker networks let containers talk to each other and to the outside world through different network drivers.

Syntaxdocker network ls

Containers 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

Example · bash
# List existing networks
docker network ls
# NETWORK ID   NAME      DRIVER
# ...          bridge    bridge
# ...          host      host
# ...          none      null

# Inspect the default bridge network
docker network inspect bridge

When 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.

Example · bash
docker network ls

Inspect a network

Shows details of the default bridge network including its subnet, gateway, and any connected containers.

Example · bash
docker network inspect bridge

Connect container to host network

Runs a container sharing the host's network stack so it can scrape host network interfaces without port mapping.

Example · bash
docker run -d \
  --network host \
  --name monitor \
  prom/node-exporter

Discussion

  • Be the first to comment on this lesson.