centos modifies docker network configuration method sharing

  • 2020-06-07 05:49:42
  • OfStack

While running ES2en-ES3en for clients with docker, it was found that some could connect to the server normally, while others could not. It is found that the client ip network segment is in conflict with the default docker0 network segment created by docker.

docker0's default network 1 is usually 172.17.0.1/24 or 192.168.0.1/24. If client ip is 172.17.111.1, then access to docker-based deployed applications will encounter network problems.

There are two solutions.

1: Run docker in host mode, but delete the default docker0 virtual network card. The docker0 virtual network card will be recreated the next time docker daemon is restarted.

2: Another solution is to modify the default docker0 network configuration and use another network segment for docker.

The following steps are the solution steps based on Scheme 2, which are feasible for personal testing.


# stop docker Server, and delete docker0 The network card 
sudo systemctl restart docker
sudo ip link set dev docker0 down
sudo brctl delbr docker0

#  Create customizations bridge0 The network segment is 10.255.254.1/24
sudo brctl addbr bridge0
sudo ip addr add 10.255.254.1/24 dev bridge0
sudo ip link set dev bridge0 up
#sudo ip link set dev bridge0 down ; sudo brctl delbr bridge0

#  Verify that the network card is running 
ip addr show bridge0

#  create docker Run configuration file (manually created if folder does not exist) 
sudo mkdir /etc/systemd/system/docker.service.d
sudo vi /etc/systemd/system/docker.service.d/docker.conf## Enter the following 

echo "[Service]
EnvironmentFile=-/etc/sysconfig/docker
ExecStart=
ExecStart=/usr/bin/dockerd $OPTIONS \
   $DOCKER_STORAGE_OPTIONS \
   $DOCKER_NETWORK_OPTIONS \
   $BLOCK_REGISTRY \
   $INSECURE_REGISTRY" > /etc/systemd/system/docker.service.d/docker.conf


#  Modify the docker The default binding network card for service startup is bridge0
echo 'DOCKER_NETWORK_OPTIONS="-b=bridge0"' >> /etc/sysconfig/docker

sudo systemctl daemon-reload

sudo systemctl restart docker

Reference link:

https://opskumu.gitbooks.io/docker/content/chapter6.html

https://www.ofstack.com/softjc/35980.html

https://docs.docker.com/engine/admin/systemd/#custom-docker-daemon-options


Related articles: