我正在使用dockerfile进行构建和映像,并且构建并成功运行,但是tomcat尚未启动 [英] I have working with dockerfile to build and image and it build and run successfully but tomcat is not up

查看:157
本文介绍了我正在使用dockerfile进行构建和映像,并且构建并成功运行,但是tomcat尚未启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Dockerfile to build an image.
Content of Docker file:

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 .生成映像时,映像已成功生成.
当我尝试使用

When I try to build the image using command docker build -t sample ., the image is build successfully.
When I try to run the command using

docker run -it --rm -p 8080:8080 sample

它显示:Starting Tomcat servlet engine tomcat7

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

But when I try to open localhost:8080, it shows webpage is not available.

请提出为什么这不起作用.

Please suggest why this is not working.

推荐答案

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

Since you are in a boot2docker environment, that means the port 8080 is mapped to 8080 in the boot2docker VM (the Linux host). Not in your PC (Windows actual host).

您还需要在Virtualbox中打开端口,以使该端口从Windows主机可见,并使浏览器访问localhost:8080.

You need to open the port as well in your Virtualbox in order for said port to be visible from your windows host, and for your browser to access localhost:8080.

有关更多信息,请参见 Boot2Docker:无法使端口转发正常工作:
(确保c:\path\to\VirtualBox位于您的PATH中)

See Boot2Docker: can't get ports forwarding to work for more:
(make sure c:\path\to\VirtualBox is in your PATH)

您可以设置永久的VirtualBox NAT端口转发:

you can set up a permanent VirtualBox NAT Port forwarding:

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

如果虚拟机已经在运行,则应运行另一个命令:

If the vm is already running, you should run this other command:

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

这篇关于我正在使用dockerfile进行构建和映像,并且构建并成功运行,但是tomcat尚未启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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