Skip to main content

Overlay Networks

Imagine multiple islands (hosts) separated by water. Normally, people on one island can’t directly talk to people on another. But if you build a bridge across the islands, suddenly they can communicate as if they were neighbors. That’s what overlay networks do in Docker - they connect containers across multiple hosts into a single, unified network.


Overlay Network Foundations

1. What is an Overlay Network?

  • An overlay network allows containers running on different Docker hosts to communicate securely.
  • It uses VXLAN (Virtual Extensible LAN) tunneling to encapsulate traffic between hosts.
  • Overlay networks are essential for multi‑host deployments and orchestration platforms like Docker Swarm.

2. Characteristics of Overlay Networks

  • Multi‑Host Communication: Containers on different machines can talk as if they’re on the same local network.
  • Isolation: Each overlay network is isolated from others.
  • Service Discovery: Built‑in DNS allows containers to resolve services by name.
  • Encryption: Traffic can be encrypted for secure communication.

3. Overlay Network Workflow

  1. Initialize a Docker Swarm cluster.
  2. Create an overlay network.
  3. Deploy services across multiple nodes.
  4. Containers in the overlay network communicate seamlessly.

4. Overlay vs Bridge Networks

Feature Bridge Network Overlay Network
Scope Single host Multi‑host
Connectivity Internal only Cross‑host
Use Case Local apps Distributed apps, microservices
Technology NAT, local DNS VXLAN tunneling, distributed DNS

Things to Remember

  • Overlay networks are the backbone of distributed containerized applications.
  • They enable cross‑host communication with built‑in service discovery.
  • Orchestration platforms rely heavily on overlay networks for scaling.

Hands‑On Lab

Step 1: Initialize a Swarm Cluster

docker swarm init

Step 2: Create an Overlay Network

docker network create -d overlay myoverlay

Step 3: Deploy a Service in the Overlay Network

docker service create --name web --network myoverlay nginx

Step 4: Scale the Service Across Nodes

docker service scale web=3
  • Multiple containers (tasks) run across different nodes but share the same overlay network.

Step 5: Inspect the Network

docker network inspect myoverlay
  • Shows connected services and containers.

Practice Exercise

  1. Initialize a Docker Swarm cluster on your machine.
  2. Create an overlay network called appnet.
  3. Deploy two services (frontend and backend) in appnet.
  4. Scale each service to multiple replicas.
  5. Test communication between frontend and backend using service names.

Visual Learning Model

Host A (Node 1)        Host B (Node 2)
   ↓                        ↓
Overlay Network (VXLAN tunnel)
   ├── Container A (frontend)
   └── Container B (backend)

The Hackers Notebook

Overlay networks connect containers across multiple hosts, enabling distributed applications to function as if they were running locally. They use VXLAN tunneling, provide built‑in DNS for service discovery, and are essential for orchestrated environments like Docker Swarm.


Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥

Updated on Dec 26, 2025