蒙珣的博客

活好当下,做好今天该做的事情。

0%

启动docker容器后网络冲突的解决办法

查看启动容器的镜像源数据

docker inspect classify_service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"Networks": {
"docker-cluster-yml_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"classify_service",
"classify_service",
"3e4da4c588e0"
],
"NetworkID": "1e720d1e75de556314b9bf0f81eae19f4fdb4b3e403d628632aa0ca73045087d",
"EndpointID": "f8eab1e55b3ca4437510c6fbc53fb92e57b63091f3bca329fc7db97f23ff91d0",
"Gateway": "172.21.0.1",
"IPAddress": "172.21.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:15:00:02",
"DriverOpts": null
}

查看IP信息

ifconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
br-1e720d1e75de: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 172.21.0.1 netmask 255.255.0.0 broadcast 172.21.255.255
inet6 fe80::42:fdff:fec1:b29d prefixlen 64 scopeid 0x20<link>
ether 02:42:fd:c1:b2:9d txqueuelen 0 (Ethernet)
RX packets 1153655 bytes 95446468 (91.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1462690 bytes 126927983 (121.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

br-f653e2f2bfa1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.1 netmask 255.255.0.0 broadcast 172.20.255.255
inet6 fe80::42:86ff:fe3b:7d prefixlen 64 scopeid 0x20<link>
ether 02:42:86:3b:00:7d txqueuelen 0 (Ethernet)
RX packets 106 bytes 7060 (6.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 944 bytes 42760 (41.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:94ff:fe7a:9366 prefixlen 64 scopeid 0x20<link>
ether 02:42:94:7a:93:66 txqueuelen 0 (Ethernet)
RX packets 76579 bytes 61234293 (58.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 137251 bytes 12661386 (12.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

可以看到该容器IP是172.21.0.1,我们需要删除桥接网络接口,然后再重建docker IP网段

删除桥接网络接口

1
2
3
4
5
yum -y install bridge-utils

brctl delbr br-1e720d1e75de


重建docker IP 网段

1
2
3
4
5
6
7
8
9
10
vim /etc/docker/daemon.json

{
"default-address-pools" : [
{
"base" : "192.168.0.0/16",
"size" : 24
}
]
}

重启docker

1
systemctl daemon-reload && systemctl restart docker

可以看到网段已经被修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
br-f653e2f2bfa1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 172.20.0.1 netmask 255.255.0.0 broadcast 172.20.255.255
inet6 fe80::42:86ff:fe3b:7d prefixlen 64 scopeid 0x20<link>
ether 02:42:86:3b:00:7d txqueuelen 0 (Ethernet)
RX packets 17203 bytes 1580215 (1.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8742 bytes 1836663 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::42:ffff:febc:c628 prefixlen 64 scopeid 0x20<link>
ether 02:42:ff:bc:c6:28 txqueuelen 0 (Ethernet)
RX packets 333 bytes 38230 (37.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 608 bytes 47778 (46.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0