Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of building Docker overlay network

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Overlay network means that by overlaying a software-defined logical network on the existing network, the original network can be retained to the maximum extent. By defining the logical network on it, the business logic can be realized and the network problems of the original data center can be solved.

Quick start

Docker cross-host network scheme

Docker native

Overlaymacvlan

Third-party scheme

Flannelweavecalico

Previously, I introduced Consul to build a cluster, so I directly choose the overlay solution that comes with docker to do it, which is a perfect combination with Consul.

Environmental preparation

Refer to the previous article "Consul Building Cluster" to prepare three virtual machines.

Ipn1172.20.20.10n2172.20.20.11n3172.20.20.12

Start consul and create a cluster on these three virtual machines

N1

[root@n1 vagrant] # consul agent-server-bootstrap-expect 3-data-dir / etc/consul.d-node=node1-bind=172.20.20.10-ui-client 0.0.0.0

N2

[root@n2 vagrant] # consul agent-server-bootstrap-expect 3-data-dir / etc/consul.d-node=node2-bind=172.20.20.11-ui-client 0.0.0.0-join 172.20.20.10

N3

[root@n3 vagrant] # consul agent-server-bootstrap-expect 3-data-dir / etc/consul.d-node=node3-bind=172.20.20.12-ui-client 0.0.0.0-join 172.20.20.10 [root@n1 vagrant] # consul membersNode Address Status Type Build Protocol DC Segmentnode1 172.20.20.10 root@n1 vagrant 8301 alive server 1.1.02 dc1 node2 172.20.20.11 dc1 node2 8301 alive server 1.1.02 dc1 node3 172.20. 20.12:8301 alive server 1.1.0 2 dc1

Configure docker

Log in N1

Modify / etc/sysconfig/docker-network to

# / etc/sysconfig/docker-networkDOCKER_NETWORK_OPTIONS=--cluster-store=consul://172.20.20.10:8500-cluster-advertise=172.20.20.10:2376

The ip part is the ip of the consul container node.

Type docker network create-d overlay myoverlay on the command line to create a network called myoverlay, and check the list of docker networks with docker network ls

[root@n1 sysconfig] # docker network lsNETWORK ID NAME DRIVER SCOPE5a8df7650e34 bridge bridge local8e574df4fb90 docker_gwbridge bridge locald69aab5b2621 host host local7301c62bca4d none null local [root@n1 sysconfig] # docker network create-d overlay myoverlay36feac75fb49edcf8920ed39109424b833501268942fb563708aa306fccfb15c [root@n1 sysconfig] # docker network lsNETWORK ID NAME DRIVER SCOPE5a8df7650e34 bridge bridge local8e574df4fb90 docker_gwbridge bridge locald69aab5b2621 host Host local36feac75fb49 myoverlay overlay global7301c62bca4d none null local

Log in N2

Modify / etc/sysconfig/docker-network to

# / etc/sysconfig/docker-networkDOCKER_NETWORK_OPTIONS=--cluster-store=consul://172.20.20.11:8500-cluster-advertise=172.20.20.11:2376

There is no need to build a new myoverlay network here, because they are a cluster. Check the network list directly

[root@n2 vagrant] # docker network lsNETWORK ID NAME DRIVER SCOPE9f2b7d40a69f bridge bridge local1d9ee9546c81 docker_gwbridge bridge locale1f72fa7710c host host local36feac75fb49 myoverlay overlay global372109bb13bc none null local

It is found that myoverlay is already among them.

Same operation n3

[root@n3 vagrant] # docker network lsNETWORK ID NAME DRIVER SCOPE14cf16d37c9b bridge bridge localca426545fedb docker_gwbridge bridge localb57d2f555fa2 host host local36feac75fb49 myoverlay overlay globalfcb5da0380e4 none null local

Start the container to verify the overlay network

Log in to N1 to start a container of busybox with myoverlay

[root@n1 sysconfig] # docker run-- network myoverlay busybox

Check the details of the busybox container. There is network-related information at the bottom.

"Networks": {"myoverlay": {"IPAMConfig": null, "Links": null, "Aliases": ["e7d558b35607"], "NetworkID": "36feac75fb49edcf8920ed39109424b833501268942fb563708aa306fccfb15c", "EndpointID": "6b1c975847b506a151940893e3ac189a7053cb34dda4ec2b5797c93f6eeb3534", "Gateway": "", "IPAddress": "10.0.0.2" "IPPrefixLen": 24, "IPv6Gateway": "," GlobalIPv6Address ":", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:0a:00:00:02"}}

You can see that the network is myoverlay ip 10.0.0.2

Log in to n2myoverlay to start a container for busybox

[root@n2 sysconfig] # docker run-- network myoverlay busybox

Check the details of the busybox container. There is network-related information at the bottom.

"Networks": {"myoverlay": {"IPAMConfig": null, "Links": null, "Aliases": ["f673ccb5ab32"], "NetworkID": "36feac75fb49edcf8920ed39109424b833501268942fb563708aa306fccfb15c", "EndpointID": "39f8e9e098ce3faf039aa60e275ec90428f86c6378f5b4c54d8682741e71673f", "Gateway": "," IPAddress ":" 10.0.0.3 " "IPPrefixLen": 24, "IPv6Gateway": "," GlobalIPv6Address ":", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:0a:00:00:03"}}

The ip of this busybox is 10.0.0.3

Enter the container, ping 10.0.0.2

[root@n2 vagrant] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf673ccb5ab32 busybox "sh" 2 minutes ago Up 2 minutes objective_ minutes objective_ [root @ N2 vagrant] # docker exec-ti f673ccb5ab32 / sh/ # ping 10.0.0.2PING 10.0.0.2 (10.0.0.2 ): 56 data bytes64 bytes from 10.0.0.2: seq=0 ttl=64 time=1.309 ms64 bytes from 10.0.0.2: seq=1 ttl=64 time=0.535 ms64 bytes from 10.0.0.2: seq=2 ttl=64 time=1.061 ms64 bytes from 10.0.0.2: seq=3 ttl=64 time=0.764 Ms ^ C-- 10.0.0.2 ping statistics-4 packets transmitted 4 packets received, 0% packet lossround-trip min/avg/max = 0.535 packet lossround-trip min/avg/max 1.309 ms

Ping is connected, and the overlay network is built successfully!

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report