Home >Operation and Maintenance >Docker >Will the ip change after docker restarts?

Will the ip change after docker restarts?

WBOY
WBOYOriginal
2022-02-07 10:54:357330browse

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.

Will the ip change after docker restarts?

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.

Will the ip change after restarting docker?

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

Will the ip change after docker restarts?

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

Will the ip change after docker restarts?

(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:

Will the ip change after docker restarts?

Check after restarting

Will the ip change after docker restarts?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn