docker 报错 non-overlapping IPv4 address pool among the defaults to assign to the network 解决方法

目录

错误现象

错误原因

解决方法

方法一 删除没使用的网络

方法二 指定网络配置

方法三 修改docker默认网络地址(推荐)


错误现象

docker-compose up 报错

Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

错误原因

Docker默认支持30个不同的自定义bridge网络,如果超过这个限制,就会提示上面的错误

使用命令 docker network ls 来查看创建的网络

[root@localhost test]# docker network ls
NETWORK ID     NAME			    DRIVER    SCOPE
d71725ca2226   bridge           bridge    local
549b36ab792b   host			    host      local
7512afa6db4c   none             null      local
9024b26834fd   test01			bridge    local
6a9389e3058f   test02			bridge    local
e1cf1dedb7dd   test03			bridge    local
fc4019ef418e   test04			bridge    local
29bba0bca81e   test05			bridge    local
7ee347eaec24   test06			bridge    local
28549a69cacc   test07			bridge    local
8df294348427   test08			bridge    local
5e56daa56894   test09			bridge    local
449033d11c39   test10			bridge    local
4eddaed16f58   test11			bridge    local
e02122c9c36a   test12			bridge    local
48f46a4c6bfc   test13			bridge    local
65f91ee63703   test14			bridge    local
d2a658f5ac03   test15			bridge    local
53b3335b2d7f   test16			bridge    local
4961f7af4876   test17			bridge    local
00074e196c25   test18			bridge    local
9853365387df   test19			bridge    local
7be93ba5d2df   test20			bridge    local
3890e77d93e3   test21			bridge    local
e711e49921d0   test22			bridge    local
754b16a98389   test23			bridge    local
0eec1dec9cc3   test24			bridge    local
80f95c508610   test25			bridge    local
d74984530daf   test26			bridge    local
ec21fcf6220c   test27			bridge    local
8b96b1d5a111   test28			bridge    local
1541b84f1724   test29			bridge    local

其中 bridge、host、none,是docker默认网络 且不能删除

统计数量:

[root@localhost test]# docker network ls | wc -l
33

除去 标题栏 和 默认的 host、none 正好有30个bridge网络,印证了 “Docker默认支持30个不同的自定义bridge网络”

解决方法

方法一 删除没使用的网络

docker network prune

这个方法比较快速的 临时解决问题

方法二 指定网络配置

修改 docker-compose.yml 文件

networks:
  default:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.1.0/24

或者 先创建网络 再指定使用这个网络配置

docker network create docker_compose_network --subnet 172.20.1.0/24
networks:
  default:
    external: 
      name: docker_compose_network 

此方法 需要修改 docker-compose.yml 文件 如果docker-compose.yml文件较多 会比较麻烦

方法三 修改docker默认网络地址(推荐)

在 /etc/docker/daemon.json 追加

{
    ...
    "default-address-pools":[
        {"base":"172.20.0.0/16","size":24},
        {"base":"172.21.0.0/16","size":24},
        {"base":"172.22.0.0/16","size":24},
        {"base":"172.23.0.0/16","size":24}
    ]
}

注意 配置中的 “...” 是配置原本的其他内容,如果没有 /etc/docker/daemon.json 文件则新建 加入 default-address-pools 的配置即可

这个配置将允许Docker分配

172.20.[0-255].0/24

172.21.[0-255].0/24

172.22.[0-255].0/24

172.23.[0-255].0/24

每个网络允许访问256个地址,总共1024个网络。

加入后需要 删除现有网络占用

docker network prune  

然后重启docker服务

service docker restart

此时再使用 docker-compose up 创建 若干容器后 

使用 docker network ls 查看

[root@localhost test]# docker network ls
NETWORK ID     NAME			    DRIVER    SCOPE
d71725ca2226   bridge           bridge    local
549b36ab792b   host			    host      local
7512afa6db4c   none             null      local
9024b26834fd   test01			bridge    local
6a9389e3058f   test02			bridge    local
e1cf1dedb7dd   test03			bridge    local
fc4019ef418e   test04			bridge    local
29bba0bca81e   test05			bridge    local
7ee347eaec24   test06			bridge    local
28549a69cacc   test07			bridge    local
8df294348427   test08			bridge    local
5e56daa56894   test09			bridge    local
449033d11c39   test10			bridge    local
4eddaed16f58   test11			bridge    local
e02122c9c36a   test12			bridge    local
48f46a4c6bfc   test13			bridge    local
65f91ee63703   test14			bridge    local
d2a658f5ac03   test15			bridge    local
53b3335b2d7f   test16			bridge    local
4961f7af4876   test17			bridge    local
00074e196c25   test18			bridge    local
9853365387df   test19			bridge    local
7be93ba5d2df   test20			bridge    local
3890e77d93e3   test21			bridge    local
e711e49921d0   test22			bridge    local
754b16a98389   test23			bridge    local
0eec1dec9cc3   test24			bridge    local
80f95c508610   test25			bridge    local
d74984530daf   test26			bridge    local
ec21fcf6220c   test27			bridge    local
8b96b1d5a111   test28			bridge    local
1541b84f1724   test29			bridge    local
77232005cdee   test30			bridge    local
84ade32cd9b3   test31			bridge    local
68f934d048c4   test32			bridge    local
a0e9b94bb66b   test33			bridge    local
91e274044951   test34			bridge    local
c556a4e8bb6b   test35			bridge    local
7779879c023d   test36           bridge    local
310740c631db   test37			bridge    local
675e5167446f   test38			bridge    local

再统计其数量

[root@localhost test]# docker network ls | wc -l
42

bridge 已经突破了30的默认限制,目前可以有1024个

此方法一劳永逸,不用修改 docker-compose.yml 文件 一次修改docker配置 永久生效 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值