Pull the image
docker pull centos
Create a custom network
docker network create --subnet=172.18.0.0/16 mynetwork
Start the centos container with fixed IP
docker run -itd --privileged --name centos1 --net mynetwork --ip 172.18.0.11 centos:latest /usr/sbin/init
docker run -itd --privileged --name centos2 --net mynetwork --ip 172.18.0.12 centos:latest /usr/sbin/init
docker run -itd --privileged --name centos3 --net mynetwork --ip 172.18.0.13 centos:latest /usr/sbin/init
View the details of the docker container (including IP)
docker ps
docker inspect 容器ID或容器名称
The above is the detailed content of How to create a centos container with fixed IP in Docker. For more information, please follow other related articles on the PHP Chinese website!