SoFunction
Updated on 2025-03-09

Docker custom bridge docker0 and docker turn on, close, restart command operation

question

After the company migrates the server, the doker0 bridge created by docker conflicts with the company's external network gateway.

This causes the external network to be unable to connect to the server.

Solution

Modify the default configuration file /etc/docker/ to configure Docker.

If not created directly

1. Close the docker service

systemctl stop docker

2. Modify the Bip

{
 "bip": "192.168.0.1/24", # Modify here .... 
}

3. Restart docker

systemctl restart docker

docker shutdown, restart, start commands

sudo service docker stop # Close orsudo systemctl stop docker
sudo service docker restart # Restart orsudo systemctl restart docker
sudo service docker start # start upsudo systemctl start docker # start up

Supplement: Modify the default ip of docker0

After the Docker service is started, a docker0 bridge will be created by default (there is a docker0 internal interface on it), which connects other physical or virtual network cards at the kernel layer, which puts all containers and local hosts on the same physical network.

Docker specifies the IP address and subnet mask of the docker0 interface by default, allowing the host and container to communicate with each other through a bridge. It also gives the MTU (the maximum transmission unit allowed by the interface), usually 1500 Bytes, or the default value supported on the host network route. These values ​​can be configured at the start of the service.

You can use edit /etc/docker/ file to add content "bip": "ip/netmask" [Don't be in the same network segment as the host]

[root@localhost /]# vi /etc/docker/
{"bip":"192.168.100.1/24"}

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.