首页 文章 docker配置网络时报错: user specifie...

docker配置网络时报错: user specified IP address is supported only when connec

发布时间:2020-11-24 15:36:22 作者:Soul-Yang 阅读量:2624

当使用 docker  run  命令运行一个容器时,给他指定ip,如 

docker run -tid --name bt-centos --network my_net  --ip 172.22.1.5  -p 80:80 -p 443:443 -p 8888:8888 -p 888:888  --privileged=true --shm-size=1g --restart always -v ~/wwwroot:/www/wwwroot pch18/baota 

报错:user specified IP address is supported only when connec

出现该问题是因为只有使用–subnet 创建的网络才能指定静态IP

如下使用  –subnet创建网络(用来指定ip段),–gateway(用来指定网关),my_net为创建的名字

docker network create --driver bridge --subnet 172.22.1.0/24 --gateway 172.22.1.1 my_net
使用上面方式创建的桥接网络,才可在启动容器时,指定 --ip 参数




  
留言
https://blog.key9.cn/
用户登录
您还没有写任何评论内容!
您已经评论过了!
只能赞一次哦!
您已经收藏啦!