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

0 Upvotes

19 comments sorted by

17

u/fletch3555 Mod 5d ago

The "things I haven't tried yet" are the "things you should be trying"

-7

u/Longjumping-Rock7662 5d ago

will it solve them?like i saw videos felt so complicated i came to reddit hahaha

7

u/fletch3555 Mod 5d ago

Have you tried? You should try. That's how we learn things

-3

u/Longjumping-Rock7662 5d ago

cool i will try them,so how much size should I aim for?

2

u/SZenC 5d ago

You might also want to study up on how build steps are stored/cached in docker and what a layer is in that context. It might then suddenly make sense why the things you listed would help

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

1

u/mbecks 5d ago

Yes you can run ‘docker image slim’ to apply efficiencies to the image up to 70%

4

u/rileywbaker 5d ago

LMAO!!!!!!!! hashtag build in public on your reddit post???

4

u/zunjae 5d ago

It’s ChatGPT slop with the instruction to create a LinkedIn 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

u/rileywbaker 5d ago

sucks dude

0

u/Longjumping-Rock7662 5d ago

my bad man my bad

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

u/Longjumping-Rock7662 7h ago

cool will do that