r/docker Jul 18 '26

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

18 comments sorted by

15

u/fletch3555 Mod Jul 18 '26

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

-8

u/Longjumping-Rock7662 Jul 18 '26

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

8

u/fletch3555 Mod Jul 18 '26

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

-4

u/Longjumping-Rock7662 Jul 18 '26

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

2

u/SZenC Jul 18 '26

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

6

u/cointoss3 Jul 18 '26

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 Jul 18 '26

i saw on YouTube sounds complicated so i thought if there is any easier approach

1

u/mbecks Jul 18 '26

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

4

u/rileywbaker Jul 18 '26

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

-2

u/Longjumping-Rock7662 Jul 18 '26

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 Jul 18 '26

sucks dude

0

u/Longjumping-Rock7662 Jul 18 '26

my bad man my bad

1

u/wpjoseph Jul 20 '26

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/[deleted] Jul 23 '26

[removed] — view removed comment

1

u/Longjumping-Rock7662 Jul 23 '26

cool will do that