SYS-CON MEDIA Authors: Yeshim Deniz, Pat Romanski, Gary Arora, Zakia Bouachraoui, Liz McMillan

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
While a hybrid cloud can ease that transition, designing and deploy that hybrid cloud still offers challenges for organizations concerned about lack of available cloud skillsets within their organization. Managed service providers offer a unique opportunity to fill those gaps and get organizations of all sizes on a hybrid cloud that meets their comfort level, while delivering enhanced benefits for cost, efficiency, agility, mobility, and elasticity.
Isomorphic Software is the global leader in high-end, web-based business applications. We develop, market, and support the SmartClient & Smart GWT HTML5/Ajax platform, combining the productivity and performance of traditional desktop software with the simplicity and reach of the open web. With staff in 10 timezones, Isomorphic provides a global network of services related to our technology, with offerings ranging from turnkey application development to SLA-backed enterprise support. Leadin...
DevOps has long focused on reinventing the SDLC (e.g. with CI/CD, ARA, pipeline automation etc.), while reinvention of IT Ops has lagged. However, new approaches like Site Reliability Engineering, Observability, Containerization, Operations Analytics, and ML/AI are driving a resurgence of IT Ops. In this session our expert panel will focus on how these new ideas are [putting the Ops back in DevOps orbringing modern IT Ops to DevOps].
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
Enterprises are striving to become digital businesses for differentiated innovation and customer-centricity. Traditionally, they focused on digitizing processes and paper workflow. To be a disruptor and compete against new players, they need to gain insight into business data and innovate at scale. Cloud and cognitive technologies can help them leverage hidden data in SAP/ERP systems to fuel their businesses to accelerate digital transformation success.
Concerns about security, downtime and latency, budgets, and general unfamiliarity with cloud technologies continue to create hesitation for many organizations that truly need to be developing a cloud strategy. Hybrid cloud solutions are helping to elevate those concerns by enabling the combination or orchestration of two or more platforms, including on-premise infrastructure, private clouds and/or third-party, public cloud services. This gives organizations more comfort to begin their digital tr...
Most organizations are awash today in data and IT systems, yet they're still struggling mightily to use these invaluable assets to meet the rising demand for new digital solutions and customer experiences that drive innovation and growth. What's lacking are potent and effective ways to rapidly combine together on-premises IT and the numerous commercial clouds that the average organization has in place today into effective new business solutions.
Keeping an application running at scale can be a daunting task. When do you need to add more capacity? Larger databases? Additional servers? These questions get harder as the complexity of your application grows. Microservice based architectures and cloud-based dynamic infrastructures are technologies that help you keep your application running with high availability, even during times of extreme scaling. But real cloud success, at scale, requires much more than a basic lift-and-shift migrati...
David Friend is the co-founder and CEO of Wasabi, the hot cloud storage company that delivers fast, low-cost, and reliable cloud storage. Prior to Wasabi, David co-founded Carbonite, one of the world's leading cloud backup companies. A successful tech entrepreneur for more than 30 years, David got his start at ARP Instruments, a manufacturer of synthesizers for rock bands, where he worked with leading musicians of the day like Stevie Wonder, Pete Townsend of The Who, and Led Zeppelin. David has ...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Addteq is a leader in providing business solutions to Enterprise clients. Addteq has been in the business for more than 10 years. Through the use of DevOps automation, Addteq strives on creating innovative solutions to solve business processes. Clients depend on Addteq to modernize the software delivery process by providing Atlassian solutions, create custom add-ons, conduct training, offer hosting, perform DevOps services, and provide overall support services.
Contino is a global technical consultancy that helps highly-regulated enterprises transform faster, modernizing their way of working through DevOps and cloud computing. They focus on building capability and assisting our clients to in-source strategic technology capability so they get to market quickly and build their own innovation engine.
When applications are hosted on servers, they produce immense quantities of logging data. Quality engineers should verify that apps are producing log data that is existent, correct, consumable, and complete. Otherwise, apps in production are not easily monitored, have issues that are difficult to detect, and cannot be corrected quickly. Tom Chavez presents the four steps that quality engineers should include in every test plan for apps that produce log output or other machine data. Learn the ste...
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...