Docker-Overlay Network
Docker-Overlay Network
In the context of Docker, an overlay network is a network that spans multiple Docker daemon hosts,
allowing containers on different hosts to communicate with each other. This becomes particularly
useful in a distributed application where containers might be running on different machines but
need to work together.
Let’s say you are working on Kubernetes cluster (k8s) or Docker Swarm where in your whole network
you have multiple machines. Inside the machines there are multiple containers are running. All
together they are on a cluster.
Let’s do some practical on this. In order to do the project/practical I will user Docker Swarm.
Docker Swarm is a native clustering and orchestration solution for Docker. It allows you to create
and manage a swarm of Docker nodes, turning them into a single, virtual Docker engine. This
enables you to deploy and manage containers at scale, providing features for high availability, load
balancing, and easy scaling of applications.
We will have separate project on Docker Swarm, for now just follow as per below.
➢ Create 2 ec2 instances. One will be our master another one will be worker.
➢ In one node which you want to make master, run docker swarm init command with below
arguments
Here in the command the ip is the public IP of you node/master which you want to make.
➢ Once you run that command you will get a token generated in your screen along with
command , you need to run it to another node which will be your worker.
Now your manger and worker are connected to each other through docker swarm.
[Service name is my-service, 2 replicas will be created using overnet network which we just created
(overlay) and nginx containers will be running]
➢ The service is the main which will help both the node’s containers to be connected through
overlay network. It’s kind of handshaking between multiple hosts containers.
➢ Below are the commands in screen shot to verify.
$docker service ls
As you can see both containers are running in same subnet range in a same Docker network which is
overlay. They both should be talk to each other.
Please do the practical with other image and try pinging. How to do that? Check my another
post/document on Custom bridge network you will get the steps.
https://www.linkedin.com/posts/avik-dutta-ba4b2952_docker-host-custom-bridge-nw-activity-
7151792517540147202-6bc-?utm_source=share&utm_medium=member_desktop
Encapsulation: When containers communicate over an overlay network, the data is encapsulated.
This means that the details of how the communication happens are abstracted away, making it
easier for containers to talk to each other without worrying about the intricacies of the underlying
network.
Swarm Mode: Docker Swarm, which is Docker's native clustering and orchestration solution, often
utilizes overlay networks. In a Swarm cluster, overlay networks help in connecting services and
distributing them across multiple nodes while ensuring they can communicate effortlessly.
Service Discovery: Overlay networks facilitate service discovery. Containers can be referred to by
their service names, and Docker's built-in DNS server takes care of routing requests to the
appropriate container. This simplifies the way containers find and communicate with each other.
Security: Overlay networks provide isolation and security. Communication within the overlay
network is confined to the containers connected to it, and the underlying physical network doesn't
need to be aware of the details of container communication.
Dynamic Updates: Overlay networks support dynamic updates. If you add or remove containers
from the network, the overlay network adapts to these changes automatically, making it flexible and
scalable.
In summary, Docker overlay networks offer a powerful solution for networking in distributed and
clustered environments. They allow containers to communicate seamlessly across multiple hosts,
providing a virtual network that simplifies the complexities of distributed application architectures.