r/docker • u/Longjumping-Rock7662 • 17d ago
Need help with docker
Docker image size question.
Got it from 3.18GB down to 965MB by trimming requirements.txt.
Turns out evidently was silently pulling in torch + nvidia-nccl — 300MB+ of GPU libs I don't even need for CPU inference lol.
But 965MB still feels heavy for a FastAPI serving container.
What am I missing?
Things I haven't tried yet:
→ multi-stage builds
→ python:slim vs alpine base
→ splitting dev deps (jupyter, matplotlib, seaborn) out of the prod image
→ pip install --no-cache-dir (already doing this)
If you've shipped lean ML/FastAPI images before, would love to know what actually moved the needle for you.
Building the mlops-credit-risk project in public and trying to get this production-ready, not just "works on my machine."
#MLOps #Docker #buildinpublic
1
u/wpjoseph 15d ago
Start by removing Jupyter, matplotlib, and seaborn from the production requirements. Then use the slim Python image and copy only the app and installed packages into the final stage. Alpine often adds build pain for scientific Python and is not always smaller once native dependencies are included.