Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a "minimal" application/container? #1790

Open
naddeoa opened this issue Sep 3, 2024 · 3 comments
Open

How to create a "minimal" application/container? #1790

naddeoa opened this issue Sep 3, 2024 · 3 comments

Comments

@naddeoa
Copy link

naddeoa commented Sep 3, 2024

Describe the issue

I have a repo up with my work for reference: https://github.com/naddeoa/nix-python-minimal-container-issue

This repo has a small python application with a few heavy dependencies (things that have native code/ require gcc, etc). When I create a container using buildLayeredImage the resulting image comes out to 415mb. When I build the same stuff using a naive Docckerfile then I get an image of size 254mb.

I know there's another issue about extra pyc files in the derivations, and that is definitely an issue, but it doesn't explain the entire difference. I can delete those pyc files and get the image that I generate with buildLayeredImage down to 281mb, and it's still a fair bit bigger than the Dockerfile version while the Dockerfile version has a bunch of junk in it like perl. Looking at the deployed layers, I can see things like and gcc sticking around even though they're not runtime dependencies. It was probably originally pulled in by my poetry dependency on faster_fifo. It seems like every dependency in the site-packages folder of the buildLayeredImage image is slightly bigger even without the pyc files. For example, pandas is 46mb instead of 43mb in the Dockerfile image, numpy is 30mb instead of 29mb, and so on.

Am I doing something wrong on the container construction side or is this not something that poetry2nix can actually solve generically?

Additional context

All files are here: https://github.com/naddeoa/nix-python-minimal-container-issue/tree/master

@declension
Copy link
Contributor

For reference the other issue: #1580

@naddeoa
Copy link
Author

naddeoa commented Sep 3, 2024

This one might also be related: #1616

@naddeoa
Copy link
Author

naddeoa commented Sep 3, 2024

As a side note, maybe we just don't care about making the image minimal because nix really can't do a perfect job there anyway? I've been playing around with Slim and for this little test I can get the image size down to a couple dozen megabytes. Even if I could make a more minimal image with poetry2nix, it would never be able to compensate for people being bad at specifying their requirements in the python ecosystem (very common) and I would still use a tool like Slim for minification when it really mattered.

Funnily enough, Slim's output on the poetry2nix container is still a few mb larger than Slim's output on the Dockerfile generated container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@naddeoa @declension and others