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.
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 withjava -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.0and-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
Dockerfilewith custom JRE — final image 120-180 MB - Layered JAR extraction for optimal Docker layer caching
docker-compose.ymlwith JVM tuning, health checks, and graceful shutdown- Container-aware memory configuration (
MaxRAMPercentageinstead of fixed-Xmx) - CI pipeline with Maven/Gradle dependency cache
Why Anubiz Engineering
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.