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

Deployment of Docker network cross-host network overlay

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

Share

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

Dcoker Network:

None network: a network with nothing.

It is common to use: enclosed space means isolation and security, such as generating random codes.

Host network: the network configuration is exactly the same as dockerhost.

Application scenario: good performance, but no flexibility, prone to port conflicts.

Brigde network: the default network driver is default, which is used to realize the communication between host network interface and virtual network interface.

Basic operating commands for deploying a network:

/ / View the network in the docker server:

[root@sqm-docker03 ~] # docker network ls

/ / View the bridged network:

[root@sqm-docker03 ~] # brctl show

/ / View the information in the container (including ip address) in the host:

[root@sqm-docker03 ~] # docker inspect test

/ / create a network:

[root@sqm-docker03 ~] # docker network create-d bridge my_net1## is followed by a custom name

/ / Custom IP address range and gateway:

[root@sqm-docker03] # docker network create-d bridge-- subnet 172.16.2.0 pick 24-- gateway 172.16.2.1 my_net2

/ / specify the ip address using a custom network when running the container:

[root@sqm-docker03] # docker run-itd-- name test2-- network my_net2-- ip 172.16.2.10 busybox

/ / add containers to a custom network to enable communication between containers:

[root@sqm-docker03 ~] # docker network connect my_net2 test

/ / Delete the network:

[root@sqm-docker02 ~] # docker network rm myolay1 # # followed by the name of the network card to be deleted

1. Communication between containers of a single host:

1) create 2 containers based on the default network of docker, box1,box2

[root@sqm-docker01] # docker run-itd-- name box1 busybox [root@sqm-docker01 ~] # docker run-itd-- name box2 busybox

2) create a custom network with bridge driver type, and create two container box3,box4 based on this network.

[root@sqm-docker01] # docker network create-d bridge my_ net1 [root @ sqm-docker01 ~] # docker run-itd-- name box3-- network my_net1 busybox [root@sqm-docker01 ~] # docker run-itd-- name box4-- network my_net1 busybox

3) create a custom network with a driver type of bridge,my_net2 and a specified network segment of 172.20.18.0 Universe 24. Create two container box5 (ip 172.20.18.6,) and box6 (172.20.18.8) based on this network

[root@sqm-docker01] # docker network create-d bridge-- subnet 172.20.18.0 take 24 my_ net2 [root @ sqm-docker01 ~] # docker run-itd-- name box5-- network my_net2-- ip 172.20.18.6 busybox [root@sqm-docker01] # docker run-itd-name box6-network my_net2-ip 172.20.18.8 busybox

4) box2 and box3 communicate with each other:

[root@sqm-docker01 ~] # docker network connect my_net1 box2

5) box4 and box5 communicate with each other:

[root@sqm-docker01 ~] # docker network connect my_net2 box4

Summary:

Containers can communicate with each other using container names, but only if the network is the custom network used.

Also, if a network segment is established while creating a custom network, the container that uses that network can also specify an ip address.

Box2 and box3 as well as box4 and box5 are different network cards and are also in different network segments, so it is necessary to build a network between the network card and the container.

2. Deploy cross-host network overlay: environment preparation:

Three docker hosts (centos7):

Docker01:172.16.1.30

Docker02:172.16.1.31

Docker03:172.16.1.32

Project actions:

(1) download profrium-consul image on docker01.

Consul: data center.

[root@sqm-docker01 ~] # docker pull progrium/consul

Run the consul service:

[root@sqm-docker01] # docker run-d-p 8500 consul-- name consul-- restart=always progrium/consul-server-bootstrap

Parameter explanation:

-d: running in the background

-p: mapped port

-h: hostname of the container

-- name: container name

-- restart=always: keep the container open

-server-bootstrap: if the service is in a cluster, it will appear as master

Log in to the consul web page:

URL: http://172.16.1.30:8500

(2) deploy on docker02:

Modify the docker configuration file:

[root@sqm-docker02 ~] # vim / usr/lib/systemd/system/docker.service

Parameter explanation:

A programming interface for / var/run/docker.sock:#docker.

-H tcp://0.0.0.0:2376:# uses the native tcp2376 port.

-- cluster-store=consul://172.16.1.30:8500:# cluster storage points to the ip address and listening port of the docker01 server.

-- cluster-advertise=ens33:2376:# collects network information from the local ens33 network card through port 2376 and stores it on consul.

After modifying the configuration file, restart the docker service:

[root@sqm-docker02 ~] # systemctl daemon-reload [root@sqm-docker02 ~] # systemctl restart docker

(3) deploy on docker03: (same as docker02 operation)

/ / you can copy the docker configuration file to docker02 on docker01:

[root@sqm-docker02 ~] # scp / usr/lib/systemd/system/docker.service root@172.16.1.32:/usr/lib/systemd/system/docker.service

/ / restart the docker service:

[root@sqm-docker03 ~] # systemctl daemon-reload [root@sqm-docker03 ~] # systemctl restart docker

Log in to the web page to view the node:

Click to enter the nodes/ option:

(4) next, create an overlay network:

Create on docker02 (custom network segment):

[root@sqm-docker02] # docker network create-d overlay-- subnet 172.16.200.0 my_olay1 24-- gateway 172.16.200.1

[root@sqm-docker02 ~] # docker network ls

# run a container (specify ip address) based on overlay network: [root@sqm-docker02 ~] # docker run-itd-- name test1-- network my_olay1-- ip 172.16.200.10 busybox# verify the ip address of test1: [root@sqm-docker02 ~] # docker exec test1 ip a

Information is automatically collected through the consul data center on the docker03 host, and there is no need to create it, so there will naturally be the same overlay network as on the docker02.

/ / create a container based on overlay on docker03 [root@sqm-docker03 ~] # docker run-itd-- name test2-- network my_olay1-- ip 172.16.200.20 busybox

(5) docke02 and docker03 communicate with each other

Communication based on ip address:

Communication based on container name:

So far, the communication between hosts has been realized by using overlay network technology.

-this is the end of this article. Thank you for reading-

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