为什么客户端无法连接到localhost:8080? [英] Why does the client can not connect to localhost:8080?

查看:564
本文介绍了为什么客户端无法连接到localhost:8080?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 dockerfile

FROM openjdk:8 as stage0
WORKDIR /opt/docker
COPY opt /opt
USER root
RUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]
RUN ["chmod", "u+x,g+x", "/opt/docker/bin/sapmock"]

FROM openjdk:8
USER root
RUN id -u demiourgos728 2> /dev/null || (( getent group 0 || groupadd -g 0 root ) && useradd --system --create-home --uid 1001 --gid 0 demiourgos728 )
WORKDIR /opt/docker
COPY --from=stage0 --chown=demiourgos728:root /opt/docker /opt/docker
EXPOSE 8080
USER 1001:0
ENTRYPOINT ["/opt/docker/bin/sapmock"]
CMD []  

如您所见,暴露了端口 8080

as you can see, that exposes the port 8080.

当我开始从图像运行容器时,如下所示:

When I start to run a container from the image as the following:

docker run -it  -p 8080:8080 db261ab225b5
Server online at localhost on the port 8080
Press RETURN to stop... 

客户端无法通过地址 localhost:8080 连接吗?

The client can not connect through the address localhost:8080 why?

推荐答案

拉杰什的答案很可能是正确的。尽管我认为您的应用更有可能只是绑定到容器内的 localhost / 127.0.0.1 将无法正常工作。确保您的应用绑定到容器内的 0.0.0.0 ,然后端口映射将起作用。

It's possible that Rajesh's answer is correct. Although I think it's more likely that your application is just binding to localhost / 127.0.0.1 inside the container, and that won't work. Make sure your app binds to 0.0.0.0 inside the container then the port mapping will work.

这篇关于为什么客户端无法连接到localhost:8080?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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