Home > Article > Operation and Maintenance > Will the ip change after docker restarts?
In docker, the ip will change after restarting; docker uses bridge connection by default, and when starting the container, it will obtain the corresponding ip address in order, which causes the ip to change every time the container is restarted.
The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.
The first time I used the docker container, I created two containers and completed the master-slave configuration of mysql. After restarting the docker container, I found the ip of the container. The address has changed, which is embarrassing. First of all, I learned that docker uses "bridge" connection by default, and when starting the container, it will obtain the IP in order. This leads to the problem that the IP address is not fixed during startup.
By default, this mode is used to start and create containers, so each time the docker container is restarted, the corresponding IP address will be obtained in order, which causes the container to be After restarting every time, the ip changes.
Let’s create a custom network to solve the problem of unstable IP.
1. Create a custom network and specify the network segment 172.17.0.0/16
2. Create a container
docker run -itd --name mysql-master-172.19.0.103 --net bindIpNetwork --ip 172.19.0.103 centos:latest /usr/sbin/init
(Note: The command copied when creating here was originally planned to be the mysql slave on 103, so I changed the name through rename. The command is: docker rename mysql-master-172.19.0.103 mysql-slave-172.19.0.103
)
3. Check the two container IPs:
Check after restarting
Recommended learning: "docker video tutorial"
The above is the detailed content of Will the ip change after docker restarts?. For more information, please follow other related articles on the PHP Chinese website!