无法访问Docker端口actix web build

egdjgwm8  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(162)

我有一个基于actix web的应用程序,我正在尝试将其容器化。当我在本地运行构建时,它运行得很好,但是当我通过docker构建它时,应用程序启动得很好,并绑定到本地docker端口,但无法从主机访问。
如何运行容器:

docker run -p 80:80 myapp

字符串
Dockerfile(abreviated):

[...] // Builds binaries
FROM debian:buster-slim
COPY --from=server-builder /usr/src/myapp/target/release/myapp /usr/bin
COPY --from=frontend-builder /usr/src/frontend/dist /static
EXPOSE 80
CMD ["myapp"]


我没有任何其他服务运行在端口80上,我尝试使用不同的主机端口。我的二进制文件没有什么问题,因为它在本地运行良好,日志显示它在docker中运行良好。这不是/static目录的错误配置,因为服务器记录连接(即使在生产版本中),并且在docker中不会到达服务器。
以下是运行docker inspect时的网络设置

"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "f7fe576d1f3c1612bb5afa94c3c360a12b0c0d464881835a0347fcadad228343",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/f7fe576d1f3c",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "b5939e954990ef71f4b69929beaf9af8f0b28f7fa9ee32363a9aefdd2f49107b",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "3eefce33be199f43e6aaa5866606a9a2da0daf25e662b510a18ed1820fb4d1d9",
                    "EndpointID": "b5939e954990ef71f4b69929beaf9af8f0b28f7fa9ee32363a9aefdd2f49107b",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }

nbysray5

nbysray51#

好吧我知道了首先,comand行参数是hostport:containerport,而不是相反。
其次,服务器只接受本地主机连接。会看到什么是与actix。调试的一个好方法是使用--network host参数和docker run

相关问题