CodeBlanks Logo Icon CodeBlanks

Network drivers

Learn bridge, host and none network drivers.

Network drivers

Docker builds container networks with drivers:

  • bridge (default): a virtual bridge on the host; containers get an IP on a private subnet.
  • host: the container uses the host's network directly; there's no isolation and no port mapping.
  • none: no network; loopback only.
  • overlay: connects several Docker hosts (Swarm).
docker run --rm --network none alpine ip addr      # only lo
docker run -d --network host nginx                 # directly on the host's port 80

When to use which?

In most cases a user-defined bridge network is the right choice (in the next lessons). The host network is chosen for applications using many ports or wanting the lowest latency, but it only fully works on Linux. none is the safest option for batch jobs that need no network at all.

docker run --rm --network none -v "$PWD":/veri alpine sha256sum /veri/arsiv.tar

Practice Choosing a network

Write two commands: run ip addr in an alpine container that is deleted when done and has no network; start a container named web from nginx in the background on the host's network.

Starter code

terminal
# buraya yaz

Sample solution

terminal
docker run --rm --network none alpine ip addr
docker run -d --name web --network host nginx

Expected output

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
e7f8091a2b3c

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does -p 8080:80 do when using --network host?

  • Nothing; port mapping is ignored Correct answer
  • It maps 8080 to 80
  • It errors and the container doesn't start
  • It opens both ports

Explanation: The container is already on the host network; the app listens on 80 directly.

2 Run the container without a network.

Question
docker run --rm --network ____ alpine ip addr
Answer
docker run --rm --network none alpine ip addr

Explanation: The none driver gives only loopback.

3 Match the drivers.

Term Meaning
bridge Default virtual bridge
host The host's network
none No network
overlay Multi-host network

All lessons in Beginner