侧边栏壁纸
博主头像
CYC的个人博客博主等级

学习使人进步

  • 累计撰写 91 篇文章
  • 累计创建 11 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Docker网络问题解决

Administrator
2023-11-16 / 0 评论 / 0 点赞 / 86 阅读 / 3373 字

Docker网络问题解决

假如防火墙关闭仍然无法访问
则检查网桥是否出现问题
创建临时网桥
容器内部ping不同宿主机ip问题
yum install bridge-utils -y

#停止docker
systemctl stop docker
#docker0
ip link set dev docker0 down
#删除docker0网桥
brctl delbr docker0
#新增一个docker0网桥
brctl addbr docker0
#增加网卡(这里ip也完全使用这个)
ip addr add 172.16.10.0/24 dev docker0
#启用网卡
ip link set dev docker0 up
#重启docker服务
systemctl restart docker


ip link delete docker0
容器内部ping不同宿主机ip问题
yum install bridge-utils -y
brctl  show
#停止docker
systemctl stop docker
#docker0
ip link set dev docker0 down
#删除docker0网桥
brctl delbr docker0
创建长期网桥
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-br0          ifdown-bnep  ifdown-ipv6  ifdown-routes    ifdown-tunnel  ifup-eth   ifup-isdn   ifup-ppp     ifup-TeamPort     network-functions
ifcfg-eno16780032  ifdown-eth   ifdown-isdn  ifdown-sit       ifup           ifup-ib    ifup-plip   ifup-routes  ifup-tunnel       network-functions-ipv6
ifcfg-lo           ifdown-ib    ifdown-post  ifdown-Team      ifup-aliases   ifup-ippp  ifup-plusb  ifup-sit     ifup-wireless
ifdown             ifdown-ippp  ifdown-ppp   ifdown-TeamPort  ifup-bnep      ifup-ipv6  ifup-post   ifup-Team    init.ipv6-global

#复制之后手动输入uuid 删除注释
[root@localhost ~]# vim ifcfg-br0
TYPE="Bridge"
UUID="${UUID}" #自己输入一个uuid
DEVICE="br0"#网桥的名字
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="172.16.1.1"#网桥的ip地址
NETMASK="255.255.0.0"#网桥所在子网的子网掩码
GATEWAY="172.16.1.1"#网桥所在子网的网关

[root@localhost ~]# systemctl restart network

[root@localhost ~]# ifconfig
br0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.16.1.1  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6 fe80::8ce4:90ff:fec6:b435  prefixlen 64  scopeid 0x20<link>
        ether 8e:e4:90:c6:b4:35  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1  bytes 90 (90.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16780032: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.201  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::20c:29ff:fe30:67f  prefixlen 64  scopeid 0x20<link>
        inet6 2409:8a3c:740d:9590:20c:29ff:fe30:67f  prefixlen 64  scopeid 0x0<global>
        inet6 2409:8a3c:740d:9590::1001  prefixlen 128  scopeid 0x0<global>
        ether 00:0c:29:30:06:7f  txqueuelen 1000  (Ethernet)
        RX packets 28528  bytes 2839314 (2.7 MiB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 37104  bytes 5286255 (5.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 32  bytes 2692 (2.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32  bytes 2692 (2.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

修改docker 默认网桥
vim /etc/docker/daemon.json

添加字段
"bridge":"br0"

启动docker启动容器后再次查看网桥
[root@localhost ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.3a29eb3d921c       no              vethaf9f97b

0

评论区