docker-compose 配置静态ip---简洁版本--ERROR: Pool overlaps with other one on this address space

之前我手动建设了自己的网络mynetwork,因此我写成下面这个时候就报错了

version: '3'
services:
        test09:
         hostname: ninetry 
         image: centos
         networks:
                  mynetwork:
                     ipv4_address: 192.168.130.120
         ports:
             - 8000:80        
         command: tail -f /dev/null 
    

networks:
 mynetwork:
       driver: bridge
       ipam:
               config:
                       - subnet: 192.168.0.0/16
Creating network "composetest_mynetwork" with driver "bridge"
ERROR: Pool overlaps with other one on this address space

改成

networks:
 mynetwork:
     external: true

加入已经存在的外部网络
再启动就可以了

great@great-PC:~/composetest$ docker-compose up -d
Recreating test09 ... done
great@great-PC:~/composetest$ cat docker-compose.yml 
version: '3'
services:
        test09:
         hostname: ninetry 
         image: centos
         container_name: test09
         networks:
                  mynetwork:
                     ipv4_address: 192.168.130.120
         ports:
             - 8000:80        
         command: tail -f /dev/null 
    

networks:
 mynetwork:
     external: true

great@great-PC:~/composetest$ 
great@great-PC:~/composetest$ docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED              STATUS                           PORTS                  NAMES
381d59cf0c30        centos              "tail -f /dev/null"   About a minute ago   Up About a minute                0.0.0.0:8000->80/tcp   test09
b1a7653bb22a        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test02
c0e350b3300b        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test06
c17e4fedfe7b        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test05
5444d21140d2        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test04
b2df5d29cdc0        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test03
8614c05210ac        centos              "tail -f /dev/null"   7 days ago           Exited (255) 8 hours ago                                test01
84322865edba        centos              "tail -f /dev/null"   7 days ago           Exited (137) About an hour ago                          test00
great@great-PC:~/composetest$ 

============================

external
如果设置为true,则指定此网络已在Compose之外创建。 docker-compose up不会尝试创建它,并且如果它不存在将会引发一个错误。

外部不能与其他网络配置键(driver,driver_opts,group_add,ipam,internal)一起使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值