r/docker • u/Longjumping-Rock7662 • 5d 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
4
u/cointoss3 5d ago
I don’t understand…you list the key things you’re supposed to do if you care about the size of a container, but they are under the “things I haven’t tried” section. It’s weird that you know to try them to solve your problem, but haven’t.
1
u/Longjumping-Rock7662 5d ago
i saw on YouTube sounds complicated so i thought if there is any easier approach
4
u/rileywbaker 5d ago
LMAO!!!!!!!! hashtag build in public on your reddit post???
-2
u/Longjumping-Rock7662 5d ago
ahahha I pasted my LinkedIn 🙂↔️ my bad,I am building my MLOps project so I use the build in public my bad
1
1
u/wpjoseph 3d 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.
1
u/Alive-Maverick 9h ago
Multi-stage build with python:3.12-slim as the final stage is the biggest single win. I've gotten FastAPI containers under 200MB that way. Avoid alpine for ML work since some packages need glibc and musl causes random install pain.
1
17
u/fletch3555 Mod 5d ago
The "things I haven't tried yet" are the "things you should be trying"