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

How to modify the address of gwbridge in docker?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Preface

Recently, a developer has encountered a problem. The network environment in which he uses host also has the situation of 172.18.0.0x16, which is repeated with the default use of 172.18.0.0x16 by docker_gwbridge as the subnet range.

Then when we encounter such a problem, we can modify the subnet range of the docker_gwbridge to avoid the connection problem of the normal 172.18.0.0and16 network segment terminal.

Docker_gwbridge introduction

The docker_gwbridge interface provides default gateway functionality for all containers and tasks that cover the network with multiple host groups. It is created on each Docker host when they join the cluster. If the IP address of interface docker_gwbridge conflicts with the address on the network, you can change the address on a host-by-host basis.

Docker_gwbridge is a local bridging network that is automatically created in the following two situations:

(1) when initializing or joining a swarm cluster, it is used to communicate between different nodes of different hosts hosts.

(2) when all the networks in the container cannot access the outside, Docker will add the docker_gwbridge network to the container to access the external network or other cluster nodes.

Modify the docker_gwbridge to generate a docker_gwbridge based on the swarm cluster:

# docker swarm init

From the figure above, we can see that docker_gwbridge defaults to 172.18.0.0Universe 16 as the subnet range.

Rebuild the docker_gwbridge network

(1) Let's take a look at all the short network information in docker:

# docker network ls

(2) then view the docker_gwbridge network details

# docker inspect docker_gwbridge

... "Containers": {"ingress-sbox": {"Name": "gateway_ingress-sbox", "EndpointID": "8388305ff33e4d4217518ae578693040f78dced947c36228e1dc7df55ae176a9", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2 max 16" "IPv6Address": ".

(3) Delete the gateway_ingress-sbox above.

# docker network disconnect docker_gwbridge gateway_ingress-sbox-f / / you need to add-f, otherwise you will say that the container cannot be found

(4) delete the original docker_gwbridge network

# docker network rm docker_gwbridge

(5) recreate the docker_gwbridge network

Docker network create\-- subnet 172.20.0.0According 20\-- gateway 172.20.0.1\-o com.docker.network.bridge.enable_icc=false\-o com.docker.network.bridge.name=docker_gwbridge\ docker_gwbridge

(6) check the network information of the host.

# ip add | grep net

Extended Learning-- swarm Cluster modifies docker_gwbridge Network

To change the subnet of the docker_gwbridge network, we need to do the following:

To alter the subnet of this interface, stop any classic containers attached to overlay networks, leave the swarm, remove the network, re-add it with the desired address, and restart classic containers as follows (must be done on a host-by-host basis): "

The main steps are as follows:

(1) get the group connection token of the relevant node (administrator or worker) role.

# docker swarm join-token worker or # docker swarm join-token manager

To add a worker to this swarm, run the following command: docker swarm join-- token SWMTKN-1-0lga4o5b38j8vg4obogubs1x7r0pctcsv38wynx0o3m0jaott6-c0hkjya6eavx9ye7xgwlj3bqi 192.168.246.176VR 2377

(2) keep a list of any superimposed classic containers. This will be used to stop and start these containers before and after network reconfiguration.

Gwbridge_containers=$ (docker network inspect docker_gwbridge-- format'{{range $k, $v: = .containers}} {{$k}} {{printf "\ n"}} {{end}'| xargs-I {} docker container ls-f is-task=false-f id= {}-- format {{.Names}}) echo ${gwbridge_containers}

(3) stop using any classic containers of docker_gwbridge:

Docker stop ${gwbridge_containers}

(4) Leave the swarm

Docker swarm leave

(5) Delete docker_gwbridge network:

Docker network rm docker_gwbridge

(6) recreate the docker_gwbridge network and set the required value:

Docker network create\-- subnet 172.20.0.0According 20\-- gateway 172.20.0.1\-o com.docker.network.bridge.enable_icc=false\-o com.docker.network.bridge.name=docker_gwbridge\ docker_gwbridge

(7) (optional) confirm the settings on docker_gwbridge:

Docker network inspect docker_gwbridge-- format'{{range $k, $v: = index .IPAM.Config 0}} {{. | printf "% s:% s" $k}} {{end}}'

(8) rejoin the cluster using the cluster connection token in step 1:

Docker swarm join-- token SWMTKN-1-0lga4o5b38j8vg4obogubs1x7r0pctcsv38wynx0o3m0jaott6-c0hkjya6eavx9ye7xgwlj3bqi 192.168.246.176VR 2377

(9) restart any superimposed classic containers:

Docker start ${gwbridge_containers}

(10) (optional) leaving and rejoining the cluster leaves unused node entries with the same hostname among the cluster members

Use the docker node rm to delete unused entries through the administrator UCP client certificate schoolbag or shell on the manager node, or UCP UI on the node screen.

Reference documentation

How do I change the docker gwbridge address?

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