gpt4 book ai didi

networking - 无法使用 podman 公开端口

转载 作者:行者123 更新时间:2023-12-02 01:53:51 27 4
gpt4 key购买 nike

我正在尝试浏览一个在 docker/podman 容器实例中启动应用程序的教程。

我尝试使用 -p port:port 和 --expose port 但似乎都不起作用。

我已使用 ss -an 确保我看到端口处于监听状态。

我已经确定没有其他任何东西试图绑定(bind)到那个端口。

无论我做什么,我永远无法访问 localhost:port 或 ip_address:port。

我觉得我从根本上错过了一些东西,但不知道下一步该去哪里。

对于要尝试的事情或要审查的文档的任何建议,我们将不胜感激。

谢谢,

肖恩

最佳答案

公开:(Reference)

Expose tells Podman that the container requests that port be open, butdoes not forward it. All exposed ports will be forwarded to randomports on the host if and only if --publish-all is also specified

根据 Containerfile 的 Redhat 文档,

EXPOSE indicates that the container listens on the specified networkport at runtime. The EXPOSE instruction defines metadata only; it doesnot make ports accessible from the host. The -p option in the podmanrun command exposes container ports from the host.

要指定端口号,

The -p option in the podman run command exposes container ports fromthe host.

示例:

podman run -d -p 8080:80 --name httpd-basic quay.io/httpd-parent:2.4

在上面的例子中,端口号 80 是容器监听/公开的端口号,我们可以通过端口号 8080 从容器外部访问它

关于networking - 无法使用 podman 公开端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69859279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com