How do you build a small Java image?
BeginnerProductionBuild Performance & CI
Answer
Build the jar with Maven/Gradle in a JDK stage (cache ~/.m2 with a cache mount), then run on a JRE-only base such as eclipse-temurin:21-jre-alpine or distroless java21. Use Spring Boot layered jars (java -Djarmode=tools extract --layers) so dependency layers cache separately from app classes, and set -XX:MaxRAMPercentage=75.
More on Build Performance & CI
How do you make Docker builds fast in CI where runners are ephemeral?BeginnerWhat are the cache backends in buildx?BeginnerWhy does `inline` cache often disappoint?AdvancedHow do you structure a Python Dockerfile for the best caching and size?IntermediateHow do you structure a Node.js production image?IntermediateHow do you build a Go image under 15 MB?Beginner