0 / 11 lessons — 0%
Lesson 07 / 11

Networking

Docker ships several network drivers; two cover almost everything you'll do:

  • bridge (default) — a private, isolated network on the host. Each container gets its own IP; containers reach each other only if they're on the same bridge network.
  • host — the container shares the host's network namespace directly. No port mapping needed, but also no isolation (Linux only).
BRIDGE NETWORK host web 172.18.0.2 db 172.18.0.3 NAT via -p HOST NETWORK host — eth0: 192.168.1.14 container shares host's network stack directly
Bridge: each container gets its own private IP, reached via published ports. Host: no isolation, no port mapping needed.
# create a user-defined bridge network docker network create app-net docker run -d --name db --network app-net postgres:16 docker run -d --name api --network app-net myapp:1.0 docker network ls docker network inspect app-net
User-defined networks > the default bridge: containers on a user-defined network get automatic DNS resolution by name. The legacy default bridge doesn't give you that without the deprecated --link flag — always create your own network.
Try it yourselfRun two containers with --network app-net, then from one, ping the other by container name. Then remove --network app-net and try again — watch it fail without a shared user-defined network.