Dockerization

Dockerize Java: Slim JRE, Fast Startup, No JDK Bloat

Java containers have a reputation for being huge — because most teams ship the full JDK. We use jlink custom runtimes and Spring Boot layered JARs to produce Java containers under 150 MB that start in seconds, not the 800 MB behemoths running on openjdk:latest.

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

Why Dockerize Java

Java applications need a JVM, but they do not need a full JDK in production. The openjdk:17 image is over 400 MB — most of which is compiler tooling your app never touches. Meanwhile, memory tuning (-Xmx, -XX:MaxRAMPercentage) is critical inside containers where the JVM can see host memory by default.

Proper containerization means shipping only the JRE modules your app uses, configuring container-aware memory limits, and leveraging layered JARs so dependency layers are cached across builds.

Our Docker Implementation for Java

Multi-stage Dockerfile with jlink custom runtime:

  • Build stage: FROM eclipse-temurin:21-jdk-alpine AS builder — runs ./mvnw -DskipTests package (or ./gradlew bootJar). For Spring Boot, extracts layers with java -Djarmode=layertools -jar app.jar extract.
  • JRE stage: Uses jlink --add-modules $(jdeps --print-module-deps app.jar) to create a custom JRE with only the required modules — typically 60-80 MB instead of 300 MB.
  • Runtime stage: FROM alpine:3.19 — copies custom JRE and layered JAR directories (dependencies, spring-boot-loader, application). Sets -XX:MaxRAMPercentage=75.0 and -XX:+UseG1GC.

Compose config includes JVM memory settings via environment variables, a health check on the actuator endpoint, and a stop_grace_period for graceful shutdown.

What You Get

  • Multi-stage Dockerfile with custom JRE — final image 120-180 MB
  • Layered JAR extraction for optimal Docker layer caching
  • docker-compose.yml with JVM tuning, health checks, and graceful shutdown
  • Container-aware memory configuration (MaxRAMPercentage instead of fixed -Xmx)
  • CI pipeline with Maven/Gradle dependency cache

Why Anubiz Engineering

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

Ready to get started?

Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.