合 docker容器不能上网的解决办法(修改docker默认网段)
docker网段和宿主机网段重复
由于docker网段默认为172.17.0.1/16
,若是宿主机的网段也和这个网段一样,那么就会导致容器不能上网:
1 2 3 4 5 6 7 8 9 10 11 | [root@lhrdb ~]# ifconfig docker0 docker0 Link encap:Ethernet HWaddr 02:42:23:EB:28:23 inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0 inet6 addr: fe80::42:23ff:feeb:2823/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:55403 errors:0 dropped:0 overruns:0 frame:0 TX packets:239883 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4516545 (4.3 MiB) TX bytes:12349550 (11.7 MiB) [root@lhrdb ~]# |
解决办法:修改docker默认网段和默认DNS地址。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | cat > /etc/docker/daemon.json <<"EOF" { "registry-mirrors": [ "https://vm1wbfhf.mirror.aliyuncs.com", "http://f1361db2.m.daocloud.io", "https://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn", "https://mirror.baidubce.com", "https://ustc-edu-cn.mirror.aliyuncs.com", "https://registry.cn-hangzhou.aliyuncs.com", "https://hub.daocloud.io" ], "bip": "172.71.0.1/16", "dns" : [ "114.114.114.114", "8.8.8.8" ] } EOF systemctl restart docker |