无法从主机连接到Docker容器 [英] Unable to connect to Docker container from host

查看:138
本文介绍了无法从主机连接到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 http://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容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆