DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Dockerizing Java MicroProfile Applications

Dockerizing Java MicroProfile Applications

Take a look at how Dockerizing and using MicroProfile adds additional functionality to your cloud-native applications.

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Mar. 29, 19 · Tutorial
Like (3)
Save
Tweet
Share
15.20K Views

Join the DZone community and get the full member experience.

Join For Free

for cloud-native applications, kubernetes and istio deliver a lot of important functionality out of the box, like ensuring resiliency and scalability. this functionality works generically for microservices, no matter in which language they have been implemented and independent from the application logic.

some cloud-native functionality, like application-specific failover functionality, metrics, and fine-grained authorization, cannot be handled by kubernetes and istio, since it needs to be handled in the business logic of the microservices.

microprofile

that's why i started to look into eclipse microprofile which is an extension to javaee to build microservices-based architectures and a great programming model for istio . in addition to the application-specific logic that istio cannot handle, it also comes with convenience functions that you typically need when developing microservices, like invoking rest apis and implementing rest apis including their documentation.

there is a microprofile starter that includes several simple samples for microprofile functionality. in order to try these features in istio, i've started to create a simple sample application .

get the code of the cloud-native starter sample.

container

the first thing you need to run microprofile applications on kubernetes is an image. microprofile is supported by several java application servers, different jvms can be used and there are different versions of all of these components. because of this, there are many different images you need to choose from.

i looked for an image that contains only components that are available as open source. here is my open liberty server.xml file and this is how my dockerfile looks like:

from openliberty/open-liberty:microprofile2-java8-openj9
add https://github.com/wasdev/sample.opentracing.zipkintracer/releases/download/1.2/liberty-opentracing-zipkintracer-1.2-sample.zip /
run unzip liberty-opentracing-zipkintracer-1.2-sample.zip -d /opt/ol/wlp/usr/ \
 && rm liberty-opentracing-zipkintracer-1.2-sample.zip
copy liberty/server.xml /config/
add target/articles.war /config/dropins/


the image contains these components:

  • openj9 0.12.1
  • openjdk 8u202-b08 from adoptopenjdk
  • open liberty 18.0.0.4
  • microprofile 2.1

there are several different images available for open liberty. i picked a community image since it comes with openj9 instead of the ibm version of openj9. unfortunately, that image doesn't seem to support microprofile 2.2 yet (at least i haven't found it).

additionally, i download and copy a file needed for zipkin tracing onto the image which you need to do manually at this point if you want to use the tracing functionality built into microprofile. this functionality is pretty useful since it allows you to see the chains of invocations between microservices.

this screenshot shows the jaeger dashboard. the bff (backend for frontend) 'web-api' microservice invokes another 'articles' service:

variations of the dockerfile

in order to avoid downloading the zipkin file every time a new image is built, i've created a slightly different dockerfile where the file is added from a local directory. the image is built with a script that downloads the file if it doesn't exist locally. alternatively, you can download the file via maven (check out the example pom.xml and example dockerfile ).

additionally, i have created another variation of the docker image so that my sample application can be installed even by people who don't have java and maven installed locally (or who have wrong java/maven versions). this dockerfile uses a multistage build .

from maven:3.5-jdk-8 as build
copy src /usr/src/app/src
copy pom.xml /usr/src/app
run mvn -f /usr/src/app/pom.xml clean package

from openliberty/open-liberty:microprofile2-java8-openj9
add liberty-opentracing-zipkintracer-1.2-sample.zip /
run unzip liberty-opentracing-zipkintracer-1.2-sample.zip -d /opt/ol/wlp/usr/ \
 && rm liberty-opentracing-zipkintracer-1.2-sample.zip
copy liberty/server.xml /config/
copy --from=build /usr/src/app/target/articles.war /config/dropins/


sample application

if you want to try microprofile on istio, use the sample application , set up a local development environment , make sure you have installed all necessary prerequisites and run these commands:

$ git clone https://github.com/nheidloff/cloud-native-starter.git
$ scripts/check-prerequisites.sh
$ scripts/deploy-articles-java-jee.sh
$ scripts/deploy-web-api-java-jee.sh


application Java (programming language) Docker (software) Kubernetes microservice

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • UUID: Coordination-Free Unique Keys
  • 10 Most Popular Frameworks for Building RESTful APIs
  • All the Cloud’s a Stage and All the WebAssembly Modules Merely Actors
  • Test Execution Tutorial: A Comprehensive Guide With Examples and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: