修改docker默认网桥

文章目录

1.说明

  • route -n
    (1)为什么docker0是up的状态?因为启动了docker容器!
    (2)通常情况下,新创建一个容器,容器内应该是可以直接ping通宿主机的,这是因为docker0网桥的存在。如果这样都不行,那么就可以断定docker0网桥有问题,需要删除原来的docker0网桥,新建一个新的!!具体方法请看操作方法2
[root@localhost ~]# ip a
docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0

2.操作方法

  • (1)删除旧网桥
$ sudo service docker stop
$ sudo ip link set dev docker0 down
$ sudo brctl delbr docker0
  • (2)手动创建一个新的网桥名称为 bridge0
$ sudo brctl addbr bridge0
$ sudo ip addr add 192.188.0.1/16 dev bridge0
$ sudo ip link set dev bridge0 up
  • (3)查看是否已经创建bridge0
ifconfig beidge0
bridge0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.1 netmask 255.255.255.0 broadcast 0.0.0.0
inet6 fe80::9044:aeff:fed1:155f prefixlen 64 scopeid 0x20<link>
ether 7e:5f:08:47:cf:48 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  • (4)创建dameon.json
vim /etc/docker/dameon.json
{
"bridge": "beidge0"
}

5、重启docker

systemctl restart docker
©️2020 CSDN 皮肤主题: 点我我会动 设计师:上身试试 返回首页