Skip to content

simple demo app that shows how to build a java war and a Docker image that uses Tomcat

Notifications You must be signed in to change notification settings

Nikunz/git-jenkins-maven-docker-tomcat-CICD-pipeline

 
 

Repository files navigation

Demo CICD Git-jenkins-maven-docker integration

Simple java project demos how to build a war file to be deployed on a Tomcat server.

Build

The build script uses mvn package to produce a demo.war file and then bundles it with a Docker image that runs Tomcat. Usage:

bin/build

What happened

  • mvn package was ran and the target/demo.war was moved into Nick-docker.war
  • a docker image was built which copied the ``Nick-docker.warto/opt/tomcatdocker/docker`. Check out the Dockerfile for details.

Here's an example of some things to check after running the build script:

$ ls pkg/demo.war
pkg/demo.war
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
Nick-docker           latest              88092dfb7325        6 minutes ago       591MB
tomcat              8.5                 a92c139758db        2 weeks ago         558MB
$

Source Url Mapping

The app is a small demo of a java servlet app. Here's the source code to url mapping:

Source Url
src/main/java/Hello.java localhost:8080/demo/Hello
src/main/webapp/index.jsp localhost:8080/demo/index.jsp

Run

Here are the summarized commands to run and test that Tomcat is serving the war file:

docker run --rm -p 8080:8080 -d demo-java
docker exec -ti $(docker ps -ql) bash
curl localhost:8080/demo/Hello
curl localhost:8080/demo/index.jsp
exit
docker stop $(docker ps -ql)

Then you can hit the the [HOSTNAME]:8080/demo/Hello and to verify that Tomcat is servering the demo.war file. You should see an html page that says "Hello World". The output should look similar:

$ docker run --rm -p 8080:8080 -d demo-java
2ba7323481fa5c4068b90f2edf38555d9551303e9c2e4c27137ab0545688555b
$ docker exec -ti $(docker ps -ql) bash
root@2ba7323481fa:/usr/local/tomcat# curl localhost:8080/demo/Hello
<h1>Hello World Hello.java</h1>
root@2ba7323481fa:/usr/local/tomcat# curl localhost:8080/demo/index.jsp
<html>
<body>
<h2>Hello World index.jsp!</h2>
</body>
</html>
root@2ba7323481fa:/usr/local/tomcat# exit
exit
$ docker stop $(docker ps -ql)
2ba7323481fa
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$

About

simple demo app that shows how to build a java war and a Docker image that uses Tomcat

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 45.4%
  • Dockerfile 31.6%
  • Shell 23.0%