Docker wagtail ERR_ADDRESS_UNREACHABLE

Docker wagtail ERR_ADDRESS_UNREACHABLE

刚刚创建了 mysite 示例https://github.com/wagtail/wagtail

运行良好python manage.py runserver

相反,如果我从 docker 构建并运行,我会得到:

无法到达地址

docker build .

docker run name

+ gunicorn mysite.wsgi:application
[2023-07-17 09:08:44 +0000] [9] [INFO] Starting gunicorn 20.0.4
[2023-07-17 09:08:44 +0000] [9] [INFO] Listening at: http://0.0.0.0:8000 (9)
[2023-07-17 09:08:44 +0000] [9] [INFO] Using worker: sync
[2023-07-17 09:08:44 +0000] [11] [INFO] Booting worker with pid: 11

docker 检查:

        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "6ae09fa43e67fd3a12a82d1f52df5969233779629d3ea36c760e2485b68fdcfc",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "8000/tcp": null
            },
            "SandboxKey": "/run/user/1000/docker/netns/6ae09fa43e67",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "df243e870b2f1006b12e54d3430481b3ce139e2ee1533ef7c05ff8543d7f49cb",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "90bd3af32cbd57398805e41e4effd604584248c1fddcb0e76048714f92aab7d8",
                    "EndpointID": "df243e870b2f1006b12e54d3430481b3ce139e2ee1533ef7c05ff8543d7f49cb",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

看起来 Docker 接口已经关闭:

systemctl status docker


● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-07-17 11:51:31 CEST; 17min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 2065 (dockerd)
      Tasks: 14
     Memory: 139.6M
        CPU: 960ms
     CGroup: /system.slice/docker.service
             └─2065 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock


lug 17 11:51:31 tec1-20en0000pc dockerd[2065]: time="2023-07-17T11:51:31.072075899+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"

知识产权

4: br-89b723d5bb07: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:55:8f:fd:a5 brd ff:ff:ff:ff:ff:ff
    inet 172.22.0.1/16 brd 172.22.255.255 scope global br-89b723d5bb07
       valid_lft forever preferred_lft forever
5: br-9c6e73ff1b4d: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:36:5e:4c:5a brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-9c6e73ff1b4d
       valid_lft forever preferred_lft forever
6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:5d:d4:50:e3 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
7: br-e461558f2119: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:f4:87:f4:51 brd ff:ff:ff:ff:ff:ff
    inet 172.19.0.1/16 brd 172.19.255.255 scope global br-e461558f2119
       valid_lft forever preferred_lft forever

Docker 版本:

Client: Docker Engine - Community
 Version:           24.0.4
 API version:       1.43
 Go version:        go1.20.5
 Git commit:        3713ee1
 Built:             Fri Jul  7 14:51:04 2023
 OS/Arch:           linux/amd64
 Context:           rootless

Server: Docker Engine - Community
 Engine:
  Version:          24.0.4
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.5
  Git commit:       4ffc614
  Built:            Fri Jul  7 14:51:04 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
 rootlesskit:
  Version:          1.1.1
  ApiVersion:       1.1.1
  NetworkDriver:    slirp4netns
  PortDriver:       builtin
  StateDir:         /tmp/rootlesskit4197084671
 slirp4netns:
  Version:          1.2.0
  GitCommit:        656041d45cfca7a4176f6b7eed9e4fe6c11e8383

答案1

要通过网络访问容器,您需要在docker run命令中定义端口映射。

相关内容