简体   繁体   English

运行docker映像时无法访问localhost:8080

[英]Can't reach localhost:8080 while running docker image

I have developed a small Java demo web app, using gradle, which I want to dockerize with WildFly. 我使用gradle开发了一个小型的Java演示Web应用程序,我想通过WildFly对其进行dockerize。 I have followed instructions from here . 我遵循了这里的指示。

The Dockerfile is: Dockerfile是:

FROM jboss/wildfly
MAINTAINER Me <me@qmail.com>

RUN /opt/jboss/wildfly/bin/add-user.sh admin Admin#70365 --silent

ADD build/libs/my-demo.war /opt/jboss/wildfly/standalone/deployments/

When I start the image with Docker and browse localhost:8080 or localhost:9990 , I get a This site can't be reached . 当我用Docker启动映像并浏览localhost:8080localhost:9990 ,我得到一个This site can't be reached

Yet, my application runs successfully on localhost:8080 when I use gradle appRun . 但是,当我使用gradle appRun时,我的应用程序可以在localhost:8080上成功运行。

What is missing? 什么东西少了?

I am under Windows 10 Home Edition. 我使用Windows 10家庭版。 I have tried on another laptop under Ubuntu 16 and face the same issue. 我曾在Ubuntu 16下尝试在另一台笔记本电脑上使用,并且遇到相同的问题。

Three things: 三件事:

1st the base image EXPOSE s only port 8080, so to be able to access port 9990 you need to add EXPOSE 9990 to your Dockerfile or --expose 9990 to your docker run call. 一个基本映像EXPOSE的唯一端口是8080,因此要访问端口9990,您需要将EXPOSE 9990添加到Dockerfile或--expose 9990--expose 9990 docker run调用。

2nd You didn't post your cmd line call, so I can only guess but you need to map the container port to a host port, example (including the additional exposed port) 2您没有发布cmd线路呼叫,因此我只能猜测,但是您需要将容器端口映射到主机端口,例如(包括附加的暴露端口)

docker run --expose 9990 -p 9990:9990 -p 8080:8080 -it my-demo

3rd If your working with docker-machine as it is still the case with Win 10 home as far as I recall, you won't have your application on localhost but at the IP of the docker-machine VM. 第三如果据我记得,如果使用Win 10 home仍然使用docker-machine,那么您的应用程序将不在localhost上,而是在docker-machine VM的IP上运行。 You can find out which IP that is by calling 您可以通过拨打电话找出哪个IP

docker-machine ip

On linux you will have your app on localhost:PORT once you add the port mapping. 在Linux上,添加端口映射后,您的应用程序将在localhost:PORT上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于 Ubuntu 16.04 Docker 容器,无法在 localhost:8080 中访问 Tomcat 默认页面 - Can't reach Tomcat default page in localhost:8080 for Ubuntu 16.04 Docker container 我的 tomcat 正在运行,但无法连接到 http://localhost:8080 - My tomcat is running but I can't connect to http://localhost:8080 Spring Boot 无法访问本地主机 Mongodb - Spring Boot can't reach localhost Mongodb TestContainers 框架无法访问 docker deamon - TestContainers Framework can't reach docker deamon 运行 docker 映像时无法到达端点 - Cant reach end-points when running docker image 运行 docker 映像时出现 FileNotFoundException - FileNotFoundException while running docker image 通过Tomcat启动Jenkins时运行一个问题(http:// localhost:8080 / jenkins /) - Running with one issue while starting Jenkins over Tomcat(http://localhost:8080/jenkins/) Tomcat 7 未在浏览器上运行 (http://localhost:8080/) - Tomcat 7 is not running on browser(http://localhost:8080/ ) Java 在 Docker 容器中运行时找不到文件 - Java can't find file while running in Docker container 我可以确定我的星巴克客户看不到我在localhost:8080上运行的Java Web应用程序吗? - Can I be sure my Java web app running on localhost:8080 is invisible from my fellow Starbucks customers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM