Q: Your Docker images are huge (3GB). CI pushes take forever. How do you reduce image size?
1. Multi-stage builds — build in one stage, copy only the artifact to a slim final stage:
#CI/CD #Docker in CI/CD #L2 #DevOps #Automation #Pipelines
🎙️ Candidate Opening & Architectural Context
""When developers encounter this build or release bottleneck, my first goal is unblocking velocity safely. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
Node image: 1GB. Node-alpine: 130MB. Huge difference.
- Multi-stage builds — build in one stage, copy only the artifact to a slim final stage:
- Use slim/alpine base images —
ubuntu= 70MB,alpine= 5MB. - Clean up in the same layer —
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*. .dockerignore— excludenode_modules,.git, test files from build context.
2️⃣
Remediation & Permanent Safeguards
FROM node:18 AS builder
WORKDIR /app
COPY . .
RUN npm ci && npm run build
FROM node:18-alpine AS runtime
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]
- Use
--no-install-recommendsfor apt installs. - Dive tool —
diveshows which layers are large and what files are in them.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Multi-stage builds — build in one stage, copy only the artifact to a slim final stage:."
⚡ 60-Second Elevator Pitch Talking Points
- Multi-stage builds — build in one stage, copy only the artifact to a slim final stage:
- Use slim/alpine base images — ubuntu = 70MB, alpine = 5MB.
- Clean up in the same layer — RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/...
Advertisement