As “the Cloud” becomes more and more widespread, now is a good time to assess how you can containerize your Java application. I assume you’re able to write a a Dockerfile around the generated JAR. However, each time the application’s code will change, the whole image will need to be rebuilt. If you’re deploying to a local Kubernetes cluster environment, this increases that much the length of the feedback loop.
In this demo-based talk, I’ll present different ways to get your Java app in a container: Dockerfile, Jib, and Cloud Native Buildpacks. We will also have a look at what kind of Docker image they generate, how they layer the images, whether those images are compatible with skaffold, etc.
2. @nicolas_frankel
Me, myself and I
Former developer, team lead, architect,
blah-blah
Developer Advocate
Curious about Containerization, Docker
& Kubernetes
3. @nicolas_frankel
Hazelcast
HAZELCAST IMDG is an operational,
in-memory, distributed computing
platform that manages data using
in-memory storage and performs
execution for breakthrough
and scale.
HAZELCAST JET is the ultra
fast, application embeddable,
3rd generation stream
processing engine for low
latency batch and stream
processing.
8. @nicolas_frankel
Building a Java app
Download the dependencies
Compile the sources to bytecode
Build the JAR
• Just a ZIP with a standard structure
14. @nicolas_frankel
Proposal 2: Jib
Standard Maven plugin
Pushes to a remote Docker repo
• Or to the local Docker daemon
Lots of configuration options
• e.g. parent image
Runs the « exploded » JAR
20. @nicolas_frankel
Solution 4: Buildpack
External tool able to understand how to
build your project
Based on the Heroku buildpack design
Project backed by CNCF
• Joined by VMWare Tanzu (Spring)
Lots of configuration options
22. @nicolas_frankel
Downsides
No version sync between the POM and the
Docker image
No choice of the parent image 😕
Run the whole build process even without
changes
Doesn’t cache the images used during the
build
• e.g. the JDK
23. @nicolas_frankel
Solution 5: Spring Boot Maven plugin
Uses the CNCF buildpack from inside
the Maven lifecycle
Lots of configuration options
skinparam dpi 150
actor " " as user
node Docker {
node JVM as jvm1 {
package "spring-in-docker.jar" as app {
component "hazelcast-client.jar" as jar
}
}
}
node JVM as jvm2 {
component Hazelcast as hz
}
() " " as api
() REST as rest
app -up- rest
hz -up- api
jar ..> api
user .right.> rest