1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Yamini Tyagi
  • 55
  • 1
  • 6

1 Answers1

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";
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC for your reply. I have made the configuration of port forwarding using VM GUI. But please let me known the commands which you have mentioned above where I need to run this command? As i am not able to figure it out where i will run this command to make sure port forwarding is working fine. – Yamini Tyagi May 13 '15 at 11:36
  • @YaminiTyagi If you have forwared the port with the VM GUI, you don't need to run those commands. If you were to run those commands, you could run them anywhere. – VonC May 13 '15 at 12:56
  • Thank you so much. I have one more query Can we give more port in VM GUI? As when i giving more ports under http request VM delete that row and only one row is available in VM GUI. – Yamini Tyagi May 14 '15 at 06:52
  • @YaminiTyagi You should be able to add as many port as you want through the Virtual Box GUI. As in http://odewahn.github.io/docker-jumpstart/boot2docker.html and http://odewahn.github.io/docker-jumpstart/images/vboxmanage.png – VonC May 14 '15 at 06:55