Docker容器配置固定IP
1.使用默认网络进行固定IP地址创建时会报错
# docker run -d --name jenkins -p 8082:8080 --restart=on-failure -v /data/jenkins:/root/.jenkins --network bridge --ip 172.17.0.5 tomcat7:base 9c018e499555e46a942e4c21bdf2647a04d701896ce9eeb53f53b8d94ee6b776 docker: Error response from daemon: user specified IP address is supported on user defined networks only.
2.根据报错提示,只有在自定义网络下才可设置固定IP,故:
# docker network create --subnet 172.18.0.0/16 mynetwork d0f630a0bb9380e06117ae9d862833db9c2f9d5d796ee893404cf97019289d81 # docker run -d --name jenkins -p 8082:8080 --restart=on-failure -v /data/jenkins:/root/.jenkins --network mynetwork --ip 172.18.0.2 tomcat7:base bb8b86a4e173cdcbb038e5ddbf8b6dcf6be4a383f49c8c5fa3ba576d5a6104e1