Welcome!

Blog Feed Post

Dockerize Tomcat/Tom EE and Oracle database applications



Docker ... Docker -- everywhere ..

Docker has gained quite a bit of popularity in simplifying operations for micro services applications. It also helps reduce cost of development and testing applications improves developer productivity it’s the portable characteristics and by allowing them to create local development environment that mimics production.

In this article, I will show how you can containerize or Dockerize a simple web application application that uses Apache Tomcat / Tom EE and Oracle database. This article assumes that you have Docker installed.

If you want to get started with Docker, review their getting started guide.

The Application

The following diagram shows the architecture for my application. I have several micro-services those are deployed in a separate Tom EE clusters and they depend on Oracle Database.  






In this blog, I will deploy all my micro services into a single container and these micro services depend on an Oracle database that is running in a separate container.  In my next blog, I will write about how to configure Oracle database in Docker.

In a future blog, I will show how you can deploy multiple services in different containers and how they can communicate with each other. 

Application Content 

Here are the war files that make different micro-services for my application.

Micro service
WAR running in Tomcat
Web front
StoreWeb.war
Credit Card
CreditService.war
Order
OrderService.war  
Shipping
DeliveryService.war
Catalog
Catalog.war


Database Configuration

The micro services depend on a database running on a separate container named orcldb.  The database is connected to a Docker bridgenetwork named appnet.

Here is the content of the context.xml (DataSource configuration) that enabled Tom EE to connect to Oracle Database.


="jdbc/HRDS" type="javax.sql.DataSource"
          driverClassName="    "
          url="jdbc:oracle:thin:@//orcldb:1521/pdb1.domain.com "
                  username="orderapp"
                  password="mypassword"
/>


Also Tomcat needs Oracle JDBC drive to connect to Oracle database and hence you need to deploy the JDBC driver (ojdbc6-11.2.0.3.jar) in the $CATALINA_HOME/lib of the Tom EE server.

The Dockerfile – Building your Docker image


Let’s see how you can use Docker to build an image that contains all artifacts you need to run your application.

You can download the Dockerfile from GitHub

Following is the content of my Dockerfile. This downloads JRE image from Docker repository, Tom EE from Apache Maven and copies all application contents (WAR files), JDBC driver, context files. You have to make appropriate changes for your environment that includes the values in the context.xml and additional JARs you might need.


FROM java:8-jre

ENV PATH /usr/local/tomee7/bin:$PATH
RUN mkdir -p /usr/local/tomee7

WORKDIR /usr/local/tomee7

ENV VALID_GPG_KEYS \
223D3A74B068ECA354DC385CE126833F9CF64915 \
    678F2D98F1FD9643811639FB622B8F2D043F71D8 \
    7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF \
    82D8419BA697F0E7FB85916EE91287822FDB81B1 \
    9056B710F1E332780DE7AF34CBAEBE39A46C4CA1 \
    A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1 \
    B7574789F5018690043E6DD9C212662E12F3E1DD \
    B8B301E6105DF628076BD92C5483E55897ABD9B9 \
    BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF \
    C23A3F6F595EBD0F960270CC997C8F1A5BE6E4C1 \
    D11DF12CC2CA4894BDE638B967C1227A2678363C \
    DBCCD103B8B24F86FFAAB025C8BB472CD297D428 \
    F067B8140F5DD80E1D3B5D92318242FE9A0B1183 \
    FAA603D58B1BA4EDF65896D0ED340E0E6D545F97

RUN set -xe \
     for key in $VALID_GPG_KEYS; do \
        gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
    done

RUN set -x \
     gpg --batch --verify tomee.tar.gz.asc tomee.tar.gz \
         tar -zxf tomee.tar.gz \
         mv apache-tomee-plus-7.0.4/* /usr/local/tomee7 \
         rm -Rf apache-tomee-plus-7.0.4 \
         rm bin/*.bat \
         rm tomee.tar.gz*
COPY *.war /usr/local/tomee7/webapps/
COPY context.xml /usr/local/tomee7/conf
COPY ojdbc6-11.2.0.3.jar /usr/local/tomee7/lib/
EXPOSE 8080
CMD ["catalina.sh", "run"]



Alternate Dockerfile with my local tar of TomEE

Here is an alternative Dockerfile that uses a Tar file that contains binary files for Tom EE version. 


FROM java:8-jre
ENV PATH /usr/local/tomee7/bin:$PATH
RUN mkdir -p /usr/local/tomee7

WORKDIR /usr/local/tomee7
COPY tomee7.tar /usr/local/tomee7
RUN tar xvf tomee7.tar
COPY *.war /usr/local/tomee7/webapps/
COPY context.xml /usr/local/tomee7/conf
RUN mkdir -p /usr/local/$host_name
COPY ojdbc6-11.2.0.3.jar /usr/local/tomee7/lib/

EXPOSE 8080
CMD ["startup.sh", "run"]


Build Your Image


You have to change to your directory that has the Dockerfile and you can use the following command to build your image. This assumes that all files such as all .war modules, context.xml, JDBC JAR files are 

docker build . -t orderapp

You will output like this. This might take few minutes to pull/download images for JRE and Tom EE from Apache Maven.

Sending build context to Docker daemon  106.4MB
Step 1/16 : FROM java:8-jre
 ---> e44d62cf8862
Step 2/16 : ENV PATH /usr/local/tomee7/bin:$PATH
 ---> Using cache
 ---> 1f4e8721dfa6
Step 3/16 : RUN mkdir -p /usr/local/tomee7
 ---> Using cache
 ---> 353199e9f026
Step 4/16 : WORKDIR /usr/local/tomee7
 ---> Using cache
 ---> bc846fadf403
Step 5/16 : ENV GPG_KEYS 223D3A74B068ECA354DC385CE126833F9CF64915     678F2D98F1FD9643811639FB622B8F2D043F71D8     7A2744A8A9AAF063C23EB7868EBE7DBE8D050EEF     82D8419BA697F0E7FB85916EE91287822FDB81B1     9056B710F1E332780DE7AF34CBAEBE39A46C4CA1     A57DAF81C1B69921F4BA8723A8DE0A4DB863A7C1     B7574789F5018690043E6DD9C212662E12F3E1DD     B8B301E6105DF628076BD92C5483E55897ABD9B9     BDD0BBEB753192957EFC5F896A62FC8EF17D8FEF     C23A3F6F595EBD0F960270CC997C8F1A5BE6E4C1     D11DF12CC2CA4894BDE638B967C1227A2678363C     DBCCD103B8B24F86FFAAB025C8BB472CD297D428     F067B8140F5DD80E1D3B5D92318242FE9A0B1183     FAA603D58B1BA4EDF65896D0ED340E0E6D545F97
 ---> Using cache
 ---> a8c51cf94777
Step 6/16 : RUN set -xe     && for key in $GPG_KEYS; do         gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key";     done
 ---> Using cache
 ---> ea35e9b7b56c
Step 7/16 : RUN set -x && curl -fSL https://repo.maven.apache.org/maven2/org/apache/tomee7/apache-tomee7/7.0... -o tomee7.tar.gz.asc    && curl -fSL https://repo.maven.apache.org/maven2/org/apache/tomee7/apache-tomee7/7.0... -o tomee7.tar.gz     && gpg --batch --verify tomee7.tar.gz.asc tomee7.tar.gz     && tar -zxf tomee7.tar.gz   && mv apache-tomee7-plus-7.0.4/* /usr/local/tomee7   && rm -Rf apache-tomee7-plus-7.0.4 && rm bin/*.bat     && rm tomee7.tar.gz*
 ---> Using cache
 ---> 26089304122d
Step 8/16 : COPY *.war /usr/local/tomee7/webapps/
 ---> Using cache
 ---> d69955ca9ee3
Step 9/16 : COPY context.xml /usr/local/tomee7/conf
 ---> Using cache
 ---> fb8e27bf03b0
Step 10/16 : COPY server.xml /usr/local/tomee7/conf
 ---> Using cache
 ---> 2f613f7784a4
Step 11/16 : COPY logging.properties /usr/local/tomee7/conf
 ---> Using cache
 ---> 5643d6775598
Step 12/16 : RUN mkdir -p /usr/local/$host_name
 ---> Using cache
 ---> acd8a6c8c765
Step 13/16 : COPY ojdbc6-11.2.0.3.jar /usr/local/tomee7/lib/
 ---> Using cache
 ---> c9ec6ee71283
Step 14/16 : COPY setenv.sh /usr/local/tomee7/bin
 ---> Using cache
 ---> cab1d0202a73
Step 15/16 : EXPOSE 8080
 ---> Using cache
 ---> 83a3d3559705
Step 16/16 : CMD catalina.sh run
 ---> Using cache
 ---> eab0027728a7
Successfully built eab0027728a7
Successfully tagged orderapp:latest


Starting Your Container

My image is now ready! You can see your images by using the following command:

docker images


The application connects to an Oracle database and the database is connected to a Docker bridge network named appnet and hence I have to connect the order app container I created in the previous step to the same bridge network. 

To create a bridge network, you have to use the following command

docker network create appnet


Let’s now start the container using the docker run command. Ensure that you have the –p parameter to map your container port to the port of your host where you are running container.


docker run -p 8080:8080 --net appnet  orderapp

Your container should start as below and you will see the standard output in the console.


11-Jan-2018 07:31:09.529 INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Starting ProtocolHandler ["http-nio-8080"]
11-Jan-2018 07:31:09.547 INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Starting ProtocolHandler ["ajp-nio-8009"]
11-Jan-2018 07:31:09.558 INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Server startup in 12272 ms

If you don’t want to see the standard output then ensure that you change the command parameter in the Docker file to startup.sh instead of catalina.sh as follows:

CMD ["startup.sh", "run"]

Your Container in Action


Now you should be able to access your application as below:


Apache Tom EE Home page: http://localhost:8080

Application Home page: http://localhost:8080/yourAppURI


Hope this blog helps to get your application Dockerized!




Read the original blog entry...

More Stories By Debu Panda

Debu Panda is a Director of Product Management at Oracle Corporation. He is lead author of the EJB 3 in Action (Manning Publications) and Middleware Management (Packt). He has more than 20 years of experience in the IT industry and has published numerous articles on enterprise Java technologies and has presented at many conferences. Debu maintains an active blog on enterprise Java at http://debupanda.blogspot.com.

Latest Stories
Your job is mostly boring. Many of the IT operations tasks you perform on a day-to-day basis are repetitive and dull. Utilizing automation can improve your work life, automating away the drudgery and embracing the passion for technology that got you started in the first place. In this presentation, I'll talk about what automation is, and how to approach implementing it in the context of IT Operations. Ned will discuss keys to success in the long term and include practical real-world examples. Ge...
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
So the dumpster is on fire. Again. The site's down. Your boss's face is an ever-deepening purple. And you begin debating whether you should join the #incident channel or call an ambulance to deal with his impending stroke. Yes, we know this is a developer's fault. There's plenty of time for blame later. Postmortems have a macabre name because they were once intended to be Viking-like funerals for someone's job. But we're civilized now. Sort of. So we call them post-incident reviews. Fires are ne...
Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism across F5's entire product suite. MacVittie has extensive development and technical architecture experience in both high-tech and enterprise organizations, in addition to network and systems administration expertise. Prior to joining F5, MacVittie was an award-winning technology editor at Network Computing Magazine where she evaluated and tested application-focused technologies including app secu...
CloudEXPO New York 2018, colocated with DevOpsSUMMIT and DXWorldEXPO New York 2018 will be held November 12-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI and Machine Learning to one location.
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of computational needs for many industries. Their solutions provide benefits across many environments, such as datacenter deployment, HPC, workstations, storage networks and standalone server installations. ICC has been in business for over 23 years and their phenomenal range of clients include multinational corporations, universities, and small busines...
This sixteen (16) hour course provides an introduction to DevOps, the cultural and professional movement that stresses communication, collaboration, integration and automation in order to improve the flow of work between software developers and IT operations professionals. Improved workflows will result in an improved ability to design, develop, deploy and operate software and services faster.
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
Authorization of web applications developed in the cloud is a fundamental problem for security, yet companies often build solutions from scratch, which is error prone and impedes time to market. This talk shows developers how they can (instead) build on-top of community-owned projects and frameworks for better security.Whether you build software for enterprises, mobile, or internal microservices, security is important. Standards like SAML, OIDC, and SPIFFE help you solve identity and authenticat...
The digital transformation is real! To adapt, IT professionals need to transform their own skillset to become more multi-dimensional by gaining both depth and breadth of a wide variety of knowledge and competencies. Historically, while IT has been built on a foundation of specialty (or "I" shaped) silos, the DevOps principle of "shifting left" is opening up opportunities for developers, operational staff, security and others to grow their skills portfolio, advance their careers and become "T"-sh...
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
Hackers took three days to identify and exploit a known vulnerability in Equifax’s web applications. I will share new data that reveals why three days (at most) is the new normal for DevSecOps teams to move new business /security requirements from design into production. This session aims to enlighten DevOps teams, security and development professionals by sharing results from the 4th annual State of the Software Supply Chain Report -- a blend of public and proprietary data with expert researc...