Pino
Pino

Reputation: 629

Can't run webapplication on tomcat using Docker

I am trying to show on my browser the webapp I've created for a school project. First of all, I've put my Dockerfile and my .war file in the same folder /home/giorgio/Documenti/dockerProject. I've written in my Dockerfile the following:

# Pull base image
From tomcat:7-jre7

# Maintainer
MAINTAINER "xyz <[email protected]">

# Copy to images tomcat path
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY file.war /home/giorgio/Documenti/apache-tomcat-7.0.72/webapps/

Then I've built the image with the command from the ubuntu shell:

docker build -t myName /home/giorgio/Documenti/dockerProjects

Finally, I've run on the shell:

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

Now, everything works fine and it doesn't show any errors, however when I want to reach localhost:8080 from my browser anything shows up, nevertheless tomcat has started running perfectly fine.

Any thoughts about a poossible problem which I can't see? Thank you!

Upvotes: 2

Views: 2243

Answers (1)

VladoDemcak
VladoDemcak

Reputation: 5259

This is your whole Dockerfile?

Because You just remove all ROOT content (step #3)

then copy war file with your application (step #4) - probably wrong folder in the question only (should be /usr/local/tomcat/webapps/)

But I don't see any endpoint or start foreground application.

I suppose you need to add:

CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

and with that just run tomcat. And It is routines to EXPOSE port, but when you are using -p docker does an implicit exposing.

So your Dockerfile should looks like:

# Pull base image
From tomcat:7-jre7

# Maintainer
MAINTAINER "xyz <[email protected]">

# Copy to images tomcat
RUN rm -rf /usr/local/tomcat/webapps/ROOT

# fixed path for copying
COPY file.war /usr/local/tomcat/webapps/

# Routine for me - optional for your case
EXPOSE 8080

# And run tomcat
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

Upvotes: 1

Related Questions