In this post we will build a Overlay network between Docker hosts. Though we can create overlay network without docker swarm mode, this post focuses on swarm cluster.
Setup Docker Swarm cluster
Commands to setup swarm cluster
#Initialize swarm on node01
#Check the nodes in swarm cluster
#add worker to swarm (run this on node02)
When you initialize a swarm or join a Docker host to an existing swarm, two new networks are created on that Docker host:
- an overlay network called ingress, which handles control and data traffic related to swarm services. When you create a swarm service and do not connect it to a user-defined overlay network, it connects to the ingress network by default.
- a bridge network called docker_gwbridge, which connects the individual Docker daemon to the other daemons participating in the swarm.
For this lab, we use two docker hosts – dockerhost01 and dockerhost02
1. Initialize swarm on dockerhost01.
Check the networks in node -> it creates docker_gwbridge and ingress networks.
2. Join dockerhost02 to the swarm cluster .
Check the networks
Check the nodes in cluster
Set up Overlay Network
Overlay network can be created just like a bridge network using docker network command. If we run the command without –attachable flag, the resulting network can be used only by services. If you want to use the network both by swarm services and standalone container use the flag.
#Create overlay network
#Create a service and attach overlay network
1. Create overlay network my-swarm-overlay in dockerhost01 .
Check the list of networks on dockerhost01
Docker inspect overlay network
Check the list of networks on dockerhost02
Why the network is not listed in dockerhost02 ? Overlay networks are available to worker nodes that have containers using them. As the host does not have any containers using the overlay network it is not available.
2. Create a service and attach the overlay network
Now check the nodes and networks in dockerhost02
Now we can see the overlay network in dockerhost02
Now run ifconfig on any node
What? Two adapters? Yes. One connects to overlay network and other one connects to docker_gwbridge. Docker_gwbridge is used for external world communication. Overlay network for east-west traffic and Docker_gwbridge for north-south traffic.
3. Test Communication .
Note downs ips of the containers connected to overlay network , in my lab they are 10.0.0.5-10.0.0.8. Now let us ping all the containers from a container.
No tags for this post.