docker Custom Bridges docker0 and docker Open Close Restart Command Operation

  • 2021-10-25 00:15:10
  • OfStack

Problem

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

Causing the external network to be unable to connect to the server.

Solution

Modify the default profil/etc/docker/daemon. json to configure Docker.

If you do not create it directly

1. Shut down the docker service


systemctl stop docker

2. Modify bip


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

3. Restart docker


systemctl restart docker

docker shutdown, restart, start commands


sudo service docker stop #  Shut down   Or 
sudo systemctl stop docker
sudo service docker restart #  Restart   Or 
sudo systemctl restart docker
sudo service docker start #  Start 
sudo systemctl start docker #  Start 

Addition: Modify the default ip of docker0

When the Docker service is started, an docker0 bridge (with an docker0 internal interface) is created by default, 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 host and container to communicate with each other through the bridge, and it also gives MTU (the maximum transmission unit that the interface is allowed to receive), which is usually 1500 Bytes, or the default value supported on the host host network route. These values can be configured when the service starts.

You can add "bip": "ip/docker/daemon. json" by editing/etc/docker/daemon file [Do not be on the same network as the host]


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

Related articles: