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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With