本地docker开启nginx服务等,
发现linux系统重启之后,无法访问,
进入容器内部,发现可以访问
但是容器外部,映射端口无法访问;
诊断之前,发现docker0没有IP绑定
bash
root@book:/etc/docker# ip addr
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:1e:fd:2a:6a brd ff:ff:ff:ff:ff:ff
inet6 fe80::42:1eff:fefd:2a6a/64 scope link
valid_lft forever preferred_lft forever
诊断之后,docker0绑定了网络: 172.17.0.1/16
bash
root@book:/etc/docker# ip addr
...
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:1e:fd:2a:6a 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:1eff:fefd:2a6a/64 scope link
valid_lft forever preferred_lft forever
诊断方法:重启docker服务
bash
root@book:/etc/docker# service docker stop
root@book:/etc/docker# service docker start
root@book:/etc/docker# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-08-08 15:09:02 UTC; 3s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1454337 (dockerd)
Tasks: 87
Memory: 46.3M
CPU: 3.739s
CGroup: /system.slice/docker.service
├─1454337 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─1454578 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5000 -container-ip 172.17.0.2 -container-port 50>
├─1454584 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5000 -container-ip 172.17.0.2 -container-port 5000
├─1454627 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 28090 -container-ip 172.18.0.2 -container-port 8>
├─1454635 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8443 -container-ip 172.17.0.3 -container-port 443
├─1454636 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 28090 -container-ip 172.18.0.2 -container-port 8090
├─1454653 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8443 -container-ip 172.17.0.3 -container-port 443
├─1454693 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8090 -container-ip 172.17.0.3 -container-port 80
├─1454706 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8090 -container-ip 172.17.0.3 -container-port 80
├─1454727 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8022 -container-ip 172.17.0.3 -container-port 22
└─1454732 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8022 -container-ip 172.17.0.3 -container-port 22
...
root@book:/etc/docker# ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=12.7 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.054 ms
root@book:/etc/docker# curl -i localhost:5000
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Tue, 08 Aug 2023 15:10:01 GMT
Content-Length: 0