0
0
Dockerdevops~10 mins

Overlay networks in Swarm in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Overlay networks in Swarm
Create Swarm Cluster
Create Overlay Network
Deploy Services
Services Join Overlay Network
Containers Communicate Across Hosts
Network Traffic Routed Securely
End
This flow shows how a Docker Swarm cluster uses overlay networks to connect services across multiple hosts securely.
Execution Sample
Docker
docker swarm init

docker network create -d overlay my_overlay

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

docker service create --name db --network my_overlay mysql
This code initializes a swarm, creates an overlay network, and deploys two services connected to that network.
Process Table
StepCommandActionResult/State Change
1docker swarm initInitialize swarm mode on current nodeNode becomes manager in swarm cluster
2docker network create -d overlay my_overlayCreate overlay network named 'my_overlay'Overlay network 'my_overlay' created and ready for services
3docker service create --name web --network my_overlay nginxDeploy 'web' service attached to 'my_overlay'Service 'web' running; containers join overlay network
4docker service create --name db --network my_overlay mysqlDeploy 'db' service attached to 'my_overlay'Service 'db' running; containers join overlay network
5Service containers startContainers on different swarm nodes join 'my_overlay'Containers can communicate securely across hosts via overlay network
6Network traffic routingSwarm routes packets between containers over encrypted VXLAN tunnelsCross-host container communication established
7EndAll services connected via overlay networkSwarm overlay network operational
💡 All services deployed and connected via overlay network; cross-host communication enabled
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Swarm ModeDisabledEnabledEnabledEnabledEnabledEnabled
Overlay Network 'my_overlay'NoneNoneCreatedCreatedCreatedCreated
Service 'web'NoneNoneRunningRunningRunningRunning
Service 'db'NoneNoneNoneRunningRunningRunning
Containers on OverlayNoneNoneNoneJoinedJoinedJoined
Key Moments - 3 Insights
Why do containers on different hosts communicate even though they are on separate machines?
Because the overlay network creates a virtual network that spans all swarm nodes, allowing containers to communicate as if on the same network (see execution_table step 5).
What happens if you try to deploy a service without specifying the overlay network?
The service will use the default bridge network, which does not span multiple hosts, so containers on different nodes cannot communicate (not shown in execution_table but implied by step 3 and 4).
How does Docker Swarm secure the network traffic between containers on different hosts?
Swarm uses encrypted VXLAN tunnels to route traffic securely between containers across hosts (see execution_table step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the overlay network created?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Check the 'Action' column for the command that creates the overlay network.
According to the variable tracker, when does the 'web' service start running?
AAfter Step 4
BAfter Step 2
CAfter Step 3
DAt Start
💡 Hint
Look at the 'Service web' row and see when its state changes to 'Running'.
If the overlay network was not created, what would happen to container communication across hosts?
AContainers would communicate normally
BContainers could not communicate across hosts
CContainers would communicate but insecurely
DContainers would crash
💡 Hint
Refer to key moment about network communication and overlay network role.
Concept Snapshot
Docker Swarm Overlay Networks:
- Use 'docker network create -d overlay <name>' to create.
- Overlay networks span multiple swarm nodes.
- Services attach with '--network <name>' to communicate.
- Traffic is routed securely via encrypted tunnels.
- Enables multi-host container communication in swarm.
Full Transcript
This visual execution shows how Docker Swarm uses overlay networks to connect containers across multiple hosts. First, swarm mode is initialized on a node. Then, an overlay network named 'my_overlay' is created. Next, two services, 'web' and 'db', are deployed and attached to this overlay network. As containers start on different swarm nodes, they join the overlay network, enabling them to communicate securely across hosts. Docker Swarm routes network traffic using encrypted VXLAN tunnels, ensuring secure communication. The variable tracker shows the state changes of swarm mode, network creation, service deployment, and container joining. Key moments clarify why overlay networks enable cross-host communication and how security is maintained. The quiz tests understanding of when the network is created, when services start, and the importance of the overlay network for communication.