Skip to content

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

@naddeoa

Description

@naddeoa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions