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:
Want to master this scenario in a live sandbox? KodeKloud's Enterprise GitOps with ArgoCD & Kubernetes Rollouts covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "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."
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.
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.
- 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/...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Performing all-at-once cutovers rather than progressive canary deployments or blue/green validation when addressing automation Direct cutovers expose 100% of user traffic to unverified code defects, maximizing the blast radius of unexpected runtime bugs.
- Configuring static long-lived cloud credentials in CI runners instead of temporary STS tokens via OIDC when addressing pipelines Static access keys stored in CI secret vaults risk exfiltration if runner environments or third-party pipeline actions are compromised.
-
Relying exclusively on client-side pre-commit hooks for secret detection without CI server gate enforcement
Developers can bypass client hooks with
git commit --no-verify; robust DevSecOps requires automated pipeline scanning with tools like Gitleaks or Trivy. - Ignoring runner disk space saturation and dangling container build cache accumulation Unpruned runner build artifacts and dangling Docker images exhaust disk inodes, causing pipeline failures unrelated to actual code quality.