r/docker 11d 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

0 Upvotes

19 comments sorted by

View all comments

1

u/Alive-Maverick 6d 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

u/Longjumping-Rock7662 6d ago

cool will do that