• Home
  • Distilled JRE Apps in Containers

Applying the Distillation Pattern to Containers.

Distilled JRE Apps in Containers

Applying the Distillation Pattern to Containers.
Distilled JRE Apps in Containers

The lab walks through a series of steps for distilling a container to its minimum to support your Java application.

For years one of Java’s strengths is write once, run anywhere (WORA) . With containers it’s now polyglot and package once, run anywhere (PORA) . All this is about writing our code to be agnostic from the target.

Java remains relevant for containers. However, it would appear between WORA and PORA there is some redundancy. If your application is running in a container and you know exactly what is in the container, why would you need a Java Runtime engine that can run anywhere? Thanks to containers they can run anywhere. What we put inside our containers should be statically defined and linked as natively as possible, at build time.

What if we could avoid putting a whole JRE in a container yet still deliver a working Java app? Blasphemy.

In this lab, you will learn how to:

    ☐ Build and run a simple Java application
    ☐ Build and run the same application with a container
    ☐ Use multi-stage technique for building containers
    ☐ Leverage Java 9+ modularity with JLink
    ☐ Compile Java to a native binary and run it from a container
    ☐ Start using GraalVM

Distillation Pattern

The distillation pattern is about applying best practices to make your containers small, simple, secure, and fast. These ideas all contribute to container distillation:

ConceptSummary
High cohesionAll things in the container are used and purposeful
Low couplingAll public access is used and purposeful
IdempotentWell tested and known versioned dependencies
ImmutableSimplicity increases when things do not change at runtime
Small attack surfaceRemove access points like ports and file mounts
Small container imagesRemove all things not used, reduce storage and transmit costs
Fast startup timeExpect ephemeral containers to fail, restart and scale
Fast execution timePerformance pays, CPUs and memory are limited resources
  • LEVEL

    Intermediate

  • DURATION

    30 minutes

  • UPDATED

    31 Dec, 2021