如何从浏览器访问在 docker 容器中运行的 tomcat? [英] How to access tomcat running in docker container from browser?

查看:84
本文介绍了如何从浏览器访问在 docker 容器中运行的 tomcat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 docker 容器中运行来自 Official Repo 的 tomcat.

I am running tomcat in my docker container from the Official Repo.

docker pull tomcat

并且按照 主页 中所述的指导方针,我已经运行了实例并启动了 Tomcat 服务器

And as per guidelines stated in the homepage I've run the instance and the Tomcat server is started

docker run -it --rm -p 8888:8080 tomcat:8.0

Tomcat 服务器在 8888 端口可用.当我执行以下命令时,我能够在 boot2docker 中获得响应

And Tomcat server is available on the port 8888. I am able to get the response in the boot2docker when I execute the following command

curl localhost:8888

但我想从安装在我的 PC 中的网络浏览器访问该页面(它不在 Virtual Box 中,即安装在我的 Windows 中的那个).我可以吗?如果有怎么办?

But I would like to access the page from my web browser installed in my PC (which is out of the Virtual Box, the one that is installed in my Windows). Can I? If so how?

推荐答案

您可能在 VirtualBox 设置中缺少端口转发规则.

You may be missing a port forwarding rule in the VirtualBox settings.

boot2docker vm > settings > Network > NAT adapter > Port forwarding

注意最后一个条目:

这样你就配置了整个链:hostPort:virtualBoxPort 然后virtualBoxPort:containerPort,如下图所示:

This way you have configured the whole chain: hostPort:virtualBoxPort then virtualBoxPort:containerPort, as shown in the following diagram:

这篇关于如何从浏览器访问在 docker 容器中运行的 tomcat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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