在Docker中启动tomcat时无法在端口8080上打开网页 [英] Not open web page on port 8080 when start tomcat inside Docker

查看:612
本文介绍了在Docker中启动tomcat时无法在端口8080上打开网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地计算机Windows 10(64位)上,我启动docker Toolbox。然后我拉出Tomcat映像并像这样运行它:

On my local machine Windows 10 (64 bit) I start docker Toolbox. Then I pull Tomcat image and run it like this:

docker run -it tomcat

成功运行。

31-Dec-2019 17:54:27.598 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
31-Dec-2019 17:54:28.849 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [1,246] ms
31-Dec-2019 17:54:28.851 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
31-Dec-2019 17:54:29.029 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [178] ms
31-Dec-2019 17:54:29.031 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
31-Dec-2019 17:54:29.128 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [90] ms
31-Dec-2019 17:54:29.129 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
31-Dec-2019 17:54:29.251 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [122] ms
31-Dec-2019 17:54:29.254 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
31-Dec-2019 17:54:30.480 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [1,226] ms
31-Dec-2019 17:54:30.499 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
31-Dec-2019 17:54:30.592 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
31-Dec-2019 17:54:30.621 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3185 ms

但是当我打开浏览器并输入

But when I open my browser and input

http://127.0.0.1:8080/

但是找不到页面

为什么?

推荐答案

@DavidMaze是正确:您所描述的情况同时存在多个问题(至少两个,也许更多,请参见下文),每个问题都分别阻止Windows主机上的浏览器访问w部署在Docker容器中的eb应用程序:

@DavidMaze is right: there are simultaneously several issues (at least two, maybe more, see below) in the situation you describe, and each issue individually prevents a browser on the Windows host from accessing the web application deployed in the Docker container:


  1. Web应用程序需要收听 0.0.0.0 特殊IP地址(不是 localhost )。

  2. -p docker run 的c>(-publish )选项。假设网络应用监听了8080端口,然后将该暴露的端口发布到主机上的80端口: docker run -p 80:8080 […] (但两个端口可以相同)

  3. 最后,在Windows上使用Docker Toolbox时,您需要确定可在其中使用网络应用程序的Docker Machine IP(不是 localhost ):如果启动时Docker Toolbox没有直接显示此信息,则可能要运行: docker-machine ip dev

  1. The web application needs to listen to the 0.0.0.0 special IP address (not localhost).
  2. The -p (--publish) option of docker run is required. Let's say the web-app listens for port 8080, then to publish this exposed port to the 80 port on the host: docker run -p 80:8080 […] (but the two ports can be the same)
  3. Finally as you use Docker Toolbox on Windows, you need to identify the Docker Machine IP where the web-app will be available (not localhost): if this information is not directly displayed by Docker Toolbox at startup, you may want to run: docker-machine ip dev.



了解更多详情




  • 关于物品1. 2.,另请参见如何将Spring-Boot Web服务转换为Docker映像?

  • 关于项目3,请参见例如无法使用我的docker映像访问Spring Boot

  • (尽管这些线程可以处理对于Spring-Boot,其中的细节相当通用)

  • For more details

    • Regarding items 1. 2., see also How to convert a Spring-Boot web service into a Docker image?
    • Regarding item 3., see e.g. Can't access Spring Boot with my docker image
    • (albeit these threads deal with Spring-Boot, the details there are quite generic)
    • 这篇关于在Docker中启动tomcat时无法在端口8080上打开网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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