5

docker默认IP地址冲突

 2 years ago
source link: https://www.wencst.com/archives/2109
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

docker默认IP地址冲突

作者: wencst 分类: docker,linux 发布时间: 2021-08-08 16:20 阅读: 12 次

一.问题描述

在公司虚拟机内开了个docker容器,发现公司内网的部分IP地址是无法访问的。

二.解决步骤

1.怀疑公司网络限制

运维查询发现有个IP段被禁止访问了,如果要访问需要单独申请。

2.怀疑本机操作问题

在不申请的情况下做了第二个操作,发现本机docker的IP地址段与该无法访问IP段比较相似。

#ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:d4:d3:b9:28  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

修改docker 的IP地址:

# vi  /etc/docker/daemon.json
{
    "bip": "192.168.100.1/24"
}

注意,此时bip一定是不能以0结尾,否则在重启docker服务时,会报错找不到网络。

操作删除原有的网络:

 ip link del docker0

如需临时修改IP网段:

docker --bip="10.1.42.1/16" -d

如果最后以为是0的话,则会报如下错误:

INFO[2020-08-21T06:33:33.159447512Z] Loading containers: start.
Error starting daemon: Error initializing network controller: Error creating default "bridge" network: failed to allocate gateway (172.30.0.0): Address already in use

如果文章对您有用,扫一下支付宝的红包,不胜感激!

欢迎加入QQ群进行技术交流:656897351(各种技术、招聘、兼职、培训欢迎加入)

Leave a Reply Cancel reply

You must be logged in to post a comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK