Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running java applications in docker with jboss or tomcat server

I have installed docker in my windows machine and run an image for java installation following instructions from "https://registry.hub.docker.com/u/dockerfile/java/" it allows me to run java commands as expected. But lets say I have a Java application which needs to be run on Jboss or tomcat. How do I create an image for this and how to add my application war file to deploy in server. As I have not much knowledge about creating docker file. It will be really very helful if you can tell how this can be done , so that I can run my application anywhere with Jboss/tomcat server using docker.

like image 940
priyank Avatar asked Aug 07 '14 11:08

priyank


People also ask

What is the difference between Tomcat and Docker?

Apache Tomcat is a Java process that contains J2EE servlets and JavaServer Pages. A Docker container is an operating system (OS) construct that contains a usable OS (as close as it can get) seperate from the host OS (as seperate as it can).

What is Tomcat Docker container?

Apache Tomcat (or simply Tomcat) is an open source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Oracle, and provides a "pure Java" HTTP web server environment for Java code to run in.


1 Answers

Create a Dockerfile like this:

FROM dockerfile/java

# Install Tomcat
RUN sudo apt-get update && sudo apt-get install tomcat7

# Add your webapp file into your docker image into Tomcat's webapps directory
# Your webapp file must be at the same location as your Dockerfile
ADD mywebapp.war /var/lib/tomcat7/webapps/

# Expose TCP port 8080
EXPOSE 8080

# Start Tomcat server
# The last line (the CMD command) is used to make a fake always-running
# command (the tail command); thus, the Docker container will keep running.
CMD sudo service tomcat7 start && tail -f /var/log/tomcat7/catalina.out

Build the image:

$ docker build -t tomcat7-test <Dockerfile's path>

And then, run it:

$ docker run -d -p 8080:8080 tomcat7-test
like image 187
Fabien Balageas Avatar answered Oct 05 '22 08:10

Fabien Balageas