I have working with dockerfile to build and image and it build and run successfully but tomcat is not up

最后都变了- 提交于 2019-12-23 01:36:13

问题


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

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

it shows: Starting Tomcat servlet engine tomcat7

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

Please suggest why this is not working.


回答1:


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).

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.

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

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";


来源:https://stackoverflow.com/questions/30182881/i-have-working-with-dockerfile-to-build-and-image-and-it-build-and-run-successfu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!