🎓 A1Learner
🔍
0 of 50 lessons completed

Networking Modes

Docker has four networking modes: bridge, host, none, and overlay. Bridge is the default, host shares the host network, none gives no network, and overlay spans many machines.

Run on the host network

This container shares the host network directly.

docker run -d --name g5-hostweb --network host nginx:1.27-alpine

Run with no network

This container gets no network at all.

docker run --rm --network none alpine:3.20 sh -c "echo no network"

Example

docker network ls --format "{{.Name}} {{.Driver}} {{.Scope}}"

Key points

  • Bridge: containers get their own network with NAT to the host. This is the default.
  • Host: the container shares the host network, with no isolation and no port mapping.
  • None: the container gets no network at all, for jobs that need none.
  • Overlay: one network across many machines, for Swarm and Kubernetes.
  • Pick the mode with --network when the container starts.

In this example, Docker lists its networks with driver and scope. The bridge, host and none entries are the built-in modes, each with its own driver. The list is the map of the modes this lesson taught.

Note

Host mode skips the network isolation containers normally give. Use it only when the app needs it.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which mode gives a container no network at all?