Prathamesh Zore’s Post

🚀 𝐇𝐨𝐰 𝐈 𝐑𝐞𝐝𝐮𝐜𝐞𝐝 𝐌𝐲 𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝐃𝐨𝐜𝐤𝐞𝐫 𝐈𝐦𝐚𝐠𝐞 𝐒𝐢𝐳𝐞 𝐛𝐲 ~𝟑𝟓𝟎 𝐌𝐁 Recently, I optimized one of my Java Spring Boot Docker images and managed to cut down nearly 350 MB from the final image size. Here’s how I did it 👇 🧱 𝐓𝐡𝐞 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 Most Java base images (like amazoncorretto:17) are JDK-based — full of development-time tools we never need in production: Compiler (javac) Debugger tools Header files Source code Mission Control, javadoc, etc. All these add unnecessary weight and easily bloat the image to 450–500 MB. And after Amazon Corretto 11, AWS stopped publishing standalone JRE images. That means for Java 17+, you’re forced to ship a full JDK even if you only need a runtime. 🔸 Note: Other distributions like Eclipse Temurin (by Adoptium) still provide official JRE builds and Docker images — a great alternative if you want a maintained lightweight runtime base. ⚙️ 𝐓𝐡𝐞 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 👉 Create a custom JRE image using the JDK itself. 1. Start from Corretto JDK 17 (official image). 2. Use jlink (available since JDK 9) to generate a minimal runtime containing only the modules your app actually needs: jlink \ --module-path $JAVA_HOME/jmods \ --add-modules java.base,java.logging,java.sql,java.xml \ --output /custom-jre \ --strip-debug \ --no-man-pages \ --no-header-files \ --compress=2 3. Use that /custom-jre as your runtime in the final Docker image. 4. Apply a multi-stage Docker build so the JDK and build tools never reach your production layer. 📦 𝐓𝐡𝐞 𝐑𝐞𝐬𝐮𝐥𝐭 Image size dropped from ~600 MB → ~250 MB Faster pull/push in CI/CD pipelines Quicker container startup Smaller attack surface 🔗 𝐁𝐨𝐧𝐮𝐬 𝐓𝐢𝐩 If you want a prebuilt runtime, check out: 👉 pnavato/amazoncorretto-jre (unofficial community image) Or use Eclipse Temurin JRE — it’s an official lightweight option from Adoptium that stays updated and secure. Still, building your own custom JRE gives you full control and ensures nothing extra is shipped to production. #Java #SpringBoot #Docker #DevOps #Microservices #CICD #AmazonCorretto #EclipseTemurin #PerformanceOptimization #CloudEngineering

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories