虚拟机挂起再恢复 docker容器无法访问
现象
虚拟机挂起后再恢复,docker内启动的容器无法访问
网上搜索的信息是ipv4转发被禁用了,通过修改/etc/sysctl.conf 中的
net.ipv4.ip_forward = 0
将这条改为1,然后重启网络即可,
sudo systemctl restart network
上面的命令在centos下可能好使,但是在ubuntu20.10下无效
sudo systemctl restart NetworkManager
上面这条命令是可行的。
挂起前的 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:13:91:e9 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.6.128/24 brd 192.168.6.255 scope global dynamic noprefixroute ens33
valid_lft 1540sec preferred_lft 1540sec
inet6 fe80::b9bb:f89b:2b73:77ff/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:da:9f:7e:fd brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:daff:fe9f:7efd/64 scope link
valid_lft forever preferred_lft forever
5: veth16781c9@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 36:f6:3e:99:39:22 brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::34f6:3eff:fe99:3922/64 scope link
valid_lft forever preferred_lft forever
7: veth81c92d7@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 4a:a4:63:50:3c:42 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::48a4:63ff:fe50:3c42/64 scope link
valid_lft forever preferred_lft forever
挂起恢复后的 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:13:91:e9 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.6.128/24 brd 192.168.6.255 scope global dynamic noprefixroute ens33
valid_lft 1767sec preferred_lft 1767sec
inet6 fe80::b9bb:f89b:2b73:77ff/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:da:9f:7e:fd brd ff:ff:ff:ff:ff:ff
5: veth16781c9@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 36:f6:3e:99:39:22 brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::34f6:3eff:fe99:3922/64 scope link
valid_lft forever preferred_lft forever
7: veth81c92d7@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 4a:a4:63:50:3c:42 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::48a4:63ff:fe50:3c42/64 scope link
valid_lft forever preferred_lft forever
可以看出docker0在恢复后 ipv4 ipv6 均没有启动成功。问题应该出在这里。
通过 ip link set docker0 up 将docker0网卡启动起来,但是看到的信息 ipv4 未分配IP
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:13:91:e9 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.6.128/24 brd 192.168.6.255 scope global dynamic noprefixroute ens33
valid_lft 1775sec preferred_lft 1775sec
inet6 fe80::b9bb:f89b:2b73:77ff/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:da:9f:7e:fd brd ff:ff:ff:ff:ff:ff
inet6 fe80::42:daff:fe9f:7efd/64 scope link
valid_lft forever preferred_lft forever
5: veth16781c9@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 36:f6:3e:99:39:22 brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::34f6:3eff:fe99:3922/64 scope link
valid_lft forever preferred_lft forever
7: veth81c92d7@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 4a:a4:63:50:3c:42 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::48a4:63ff:fe50:3c42/64 scope link
valid_lft forever preferred_lft forever
Docker 网络配置
Docker端口映射及虚拟机挂起重开无法远程访问的理解
玩转Docker Network
Docker 网络之理解 bridge 驱动
docker 容器默认的网络模型