ทวีตที่ปักหมุด
🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐
7.5K posts

🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐
@jcobjoss777
📚 Software Developer | Backend Engineer | Javalover #Java ☕ | #microservicios #Spring 🌱 | Apasionado por la ciberseguridad 🤖 | human drummer 🥁| Anime
Detras de un proxy เข้าร่วม Kasım 2015
533 กำลังติดตาม191 ผู้ติดตาม
🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐 รีทวีตแล้ว
🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐 รีทวีตแล้ว

🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐 รีทวีตแล้ว
🇪🇨 𝑱𝒂𝒄𝒐𝒃𝒐 รีทวีตแล้ว

How to reduce Docker image size from 846 MB to 2.5 MB (a 99.7% reduction)📚
The Problem (Before):
-> Single-stage Dockerfile
-> Heavy base image (e.g., full Ubuntu/Debian or bloated builder like golang with all dev tools)
-> Build dependencies, caches, temporary files, and unnecessary OS packages all shipped to production
-> Result: 846 MB bloated image -> slow pulls, high storage costs, larger attack surface.
The Solution (After) – Key Techniques Applied Step-by-Step:
1. Switch to a Lightweight Builder Base:
-> Started with golang: alpine (or equivalent slim builder) instead of the full image. This alone dropped it significantly (e.g., from 846 MB to ~300 MB).
2. Multi-Stage Builds (The Game Changer):
-> Stage 1 (Builder): Use a full builder image with all tools, compile the app, and produce a small binary/artifact.
-> Stage 2 (Runtime): Start fresh with a tiny base like Alpine (~5 MB) or even scratch/distroless (near-zero OS).
-> Only COPY the final compiled binary (and minimal runtime deps) from the builder stage. Everything else (compilers, caches, dev packages) stays behind in the builder stage and never reaches production.
3. Additional Optimizations:
-> Combine RUN commands and clean up in the same layer (rm -rf /var/cache/apk/* etc.).
-> Use .dockerignore to exclude tests, docs, git, node_modules, etc. from build context.
-> For Go: Build with CGO_ENABLED=0 GOOS=linux for a static binary.
-> Final runtime base: Minimal Alpine + only the binary -> 2.5 MB.
Result: 846 MB -> 2.5 MB. Faster deploys, cheaper storage, better security.

English

@LatAmCulture Bro, Quito es increíble y eso que vine de vivir en Cuenca
Español



















