Docker Swarm 101 : Overlay network and services

The docker0 bridge is a Linux virtual bridge that docker uses to connect containers that live on the same host.

To make it possible for the containers on different nodes to communicate with each other, we would need to publish the containers port and define routing tables, masquerading and port forwarding on the different hosts.

The overlay network help us set up a network that spans all the nodes and makes it possible for containers on different hosts to communicate, 

Overlay networks:

The overlay network helps us to easily set up a network that would connect containers on different hosts (that are in the docker cluster).

We create the overlay network using the below command:

The overlay network spans all the docker cluster (swarm).

After creating the overlay network, we can attach the containers to it while creating them using the below command:

We can also attach a docker service that creates two replicas of the same container to the overlay_1 network:

A service deploys a number of replicas of the same container. The service also restarts if it crashes, moves it to different node when necessary,...

Below is an example of what an overlay network looks like.
It connects containers that live on different nodes of the cluster:

Using an ingress service (laod-balancer): 

An ingress load-balancer allows us to map two or more containers to the same port on the host which is not possible without a load-balancer since we would have a conflict of ports (two containers publish the same port).

A service creates an ingress network with a load-balancer, so even if two containers are mapped to the same host port the load-balancer routes the packets to either of these containers:

Docker built-in DNS:

Docker has a built in DNS server ( that maps a container's name to an IP address making it easier to track containers even if they restart with different IP addresses.


Leave as a comment: