IT 3300 : Virtualization

Docker — Networking

The question

  • Containers need to talk: to the outside world, and to each other
  • Docker gives each container a network interface and manages the wiring

Network drivers

  • bridge — default; a private network on one host
  • host — share the host's network stack (no isolation)
  • none — no networking at all
  • overlay — a network spanning multiple hosts

The default bridge

  • Containers get a private IP on docker0

  • Reach the outside via NAT

  • Publish a port to expose a service:

      docker run -d -p 8080:80 nginx
    

User-defined bridge networks

  • Create your own network so containers can find each other by name

      docker network create appnet
      docker run -d --name db --network appnet postgres
      docker run -d --name web --network appnet myapp
    
  • web can reach the database at the hostname db — built-in DNS

Why named networks matter

  • On the default bridge, containers can only reach each other by IP
  • On a user-defined network, Docker provides automatic DNS
  • This name-based discovery is exactly what Compose automates next

Overlay networks

  • Span multiple Docker hosts (Swarm)
  • Foreshadows how Kubernetes gives every pod a routable IP across nodes
  • Awareness for now; single-host bridges cover our labs

Inspecting networks

  • docker network ls — list networks
  • docker network inspect appnet — see connected containers and IPs
  • docker network connect / disconnect — attach/detach live

Lab goals

  • Create a user-defined network with a web app and a database
  • Have the app connect to the DB by container name
  • Confirm the default bridge does not resolve names the same way