【问题标题】:I have working with dockerfile to build and image and it build and run successfully but tomcat is not up我正在使用 dockerfile 构建和映像,它构建和运行成功,但 tomcat 没有启动
【发布时间】:2015-05-12 05:58:03
【问题描述】:

我正在使用 Dockerfile 构建映像。
Docker 文件内容:

FROM ubuntu
# Update Ubuntu
RUN apt-get update && apt-get -y upgrade
# Add oracle java 7 repository
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get -y update
# Accept the Oracle Java license
RUN echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | debconf-set-selections
# Install Oracle Java
RUN apt-get -y install oracle-java7-installer
# Install tomcat
RUN apt-get -y install tomcat7
RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle" >> /etc/default/tomcat7
EXPOSE 8080
# Download Slashdot homepage
RUN mkdir /var/lib/tomcat7/webapps/slashdot
RUN wget http://www.slashdot.org -P /var/lib/tomcat7/webapps/slashdot
# Start Tomcat, after starting Tomcat the container will stop. So use a 'trick' to keep it running.
CMD service tomcat7 start && tail -f /var/lib/tomcat7/logs/catalina.out

当我尝试使用命令docker build -t sample . 构建镜像时,镜像构建成功。
当我尝试使用

运行命令时
docker run -it --rm -p 8080:8080 sample

它显示:Starting Tomcat servlet engine tomcat7

但是当我尝试打开localhost:8080 时,它显示webpage is not available

请说明为什么这不起作用。

【问题讨论】:

  • 您是否已经使用 Google 等搜索引擎搜索过解决方案?

标签: tomcat docker tomcat7 boot2docker


【解决方案1】:

由于您处于 boot2docker 环境中,这意味着端口 8080 映射到 boot2docker VM(Linux 主机)中的 8080。不在您的 PC(Windows 实际主机)中。

您还需要在 Virtualbox 中打开该端口,以使您的 Windows 主机可以看到该端口,并让您的浏览器访问 localhost:8080。

更多信息请见Boot2Docker: can't get ports forwarding to work
(确保c:\path\to\VirtualBox 在您的PATH 中)

你可以设置一个永久的 VirtualBox NAT 端口转发:

VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8080,tcp,,8080,,8080";

如果 vm 已经在运行,你应该运行这个其他命令:

VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port8080,tcp,,8080,,8080";

【讨论】:

  • 感谢@VonC 的回复。我已经使用 VM GUI 进行了端口转发的配置。但是请让我知道你上面提到的命令我需要在哪里运行这个命令?因为我无法弄清楚我将在哪里运行此命令以确保端口转发工作正常。
  • @YaminiTyagi 如果您使用 VM GUI 转发了端口,则无需运行这些命令。如果你要运行这些命令,你可以在任何地方运行它们。
  • 非常感谢。我还有一个查询 我们可以在 VM GUI 中提供更多端口吗?当我在 http 请求 VM 下提供更多端口时,删除该行,VM GUI 中只有一行可用。
  • @YaminiTyagi 您应该能够通过 Virtual Box GUI 添加任意数量的端口。如odewahn.github.io/docker-jumpstart/boot2docker.htmlodewahn.github.io/docker-jumpstart/images/vboxmanage.png
猜你喜欢
  • 1970-01-01
  • 2021-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-22
  • 2017-04-16
  • 1970-01-01
  • 2012-03-16
相关资源
最近更新 更多