无法从主机连接到Docker容器

编程入门 行业动态 更新时间:2024-10-28 15:34:05
本文介绍了无法从主机连接到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

第一次使用Docker,所以我可能会犯一个菜鸟错误,但这是可行的。我正在尝试使用 reactioncommerce / reaction 图片,它似乎可以正常运行。但是,我似乎无法从主机连接到服务器。

Just using Docker for the first time so I'm probably making a rookie mistake, but here goes. I am trying to use the reactioncommerce/reaction image, and it appears to run correctly. However, I cannot seem to connect to the server from the host.

我正在运行 docker run -p:8080 -it反应,如 Docker Hub页面上所建议,然后尝试通过在主机上的浏览器上转到 http:// localhost:8080 ,但无法建立连接。我要去哪里了?

I am running docker run -p :8080 -it reaction as suggested on the Docker Hub page, then trying to access it by going to localhost:8080 on a browser on the host, but no connection can be made. Where am I going wrong?

我正在Linux Mint主机上运行。

I'm running on a Linux Mint host.

推荐答案

我认为您的问题将是您的 -p (发布)标志。假设您的容器实际上在端口8080上侦听-尝试 -p 8080:8080 会将本地主机:8080映射到您的容器。 (嗯,从技术上讲,它将映射 0.0.0.0:8080 ,它是所有地址-包括外部地址)

I think your problem will be your -p (publish) flag. Assuming your container is actually listening on port 8080 - try -p 8080:8080 which will map localhost:8080 to your container. (Well, technically it'll map 0.0.0.0:8080 which is all addresses - including external)

但是我认为,如果您未在左侧指定某些内容,则会得到一个随机映射的端口号-您应该可以在 docker ps 或使用 docker port 命令。

But I think if you're not specifying something on the left hand side, you're getting a random port number mapped - you should be able to see this in docker ps or using the docker port command.

当您运行 docker run -it 时,将以交互方式启动它-并且它应该以 docker file(除非另有说明)。我认为这将是您想要的服务,但我不知道该应用程序。您还可以使用 -d 标志,该标志在后台运行容器。

When you run docker run -it you start it interactively - and it should start 'whatever is defined in the docker file' unless you specify otherwise. I assume this will be a service you want, but I don't know that app. You can also use the -d flag, that runs the container in the background.

更多推荐

无法从主机连接到Docker容器

本文发布于:2023-10-14 12:28:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1491058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   容器   主机   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!