linux服务器重启之后docker容器内部网络不通问题
解决方案:重启网卡docker0
整体操作:

root@book:~# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "25f83fdf8aaa0d7ff5a25deb4c07685c75704c70159478b2e28f7e11d96fdc58",
        "Created": "2023-08-03T15:22:04.625718573+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "42770299d8b60a9e9c3beaa7af4b1809721618a470b48ad5a13e11422b01595c": {
                "Name": "exciting_curie",
                "EndpointID": "090e4c2a0c30da996061ddceb7126f62fc449432b9c7cd189de73d374783a6ea",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "8f423ac10b7df9f179298ac579bc4655f6ca423b11fe7f6429f37e0e2f1f19dd": {
                "Name": "eager_ganguly",
                "EndpointID": "ad231dddcd3a11a54da1d97be9257a6f48c8b0c557b324f9bf764e5461a6076c",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

root@book:~# ifconfig docker0 down
root@book:~# curl -i localhost:18000
^C
root@book:~# ifconfig docker0 up
root@book:~# curl -i localhost:18000
HTTP/1.1 200 OK
Server: nginx/1.25.1
Date: Tue, 08 Aug 2023 02:15:09 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 13 Jun 2023 15:08:10 GMT
Connection: keep-alive
ETag: "6488865a-267"
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

可以看到,docker的默认方式是桥接:bridge
docker的虚拟网卡为docker0
手动关闭docker0

ifconfig docker0 down

然后,看下效果,发现容器内部网络不通;

curl -i localhost:18000

启动网卡docker0后,可以正常访问容器内部;

ifconfig docker0 up
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐