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

Slim down the Docker image. #384

Merged
merged 1 commit into from
Feb 1, 2023
Merged

Conversation

danielballan
Copy link
Member

The image produced by #382 is large:

ghcr.io/bluesky/tiled      v0.1.0a81   475c9aaae631  14 hours ago    1.67 GB

We can cut the size in half by using a stripped-down Debian image, python:3.10-slim. Unlike alpine, the slim variant still uses glibc, and Python's manylinux wheels run on it. More info the excellent Normcore talk, "How small can I get this Docker container?".

localhost/tiled-slim       latest      964bf88d7066  13 minutes ago  860 MB

In #382 there was a nonsensical multi-stage build being used, equivalent to:

FROM python:3.10-slim as X
...

FROM X as Y
...

The second stage has no effect because it builds directly on top of the previous stage, discarding nothing. (This was introduced by me, due to a fuzzy mental model of layering.) Consolidating those to stages into one produces an image of exactly the same size, as expected:

localhost/tiled-slim-1s    latest      468085b843ce  5 minutes ago   860 MB

If we use multi-stage builds properly, we can keep the source tree out of the final image and shave off another 37 MB:

localhost/tiled-slim-ms    latest      0ed63eef6a81  2 minutes ago   823 MB

Using Dive I inspected where that size is coming from. The vast majority (664 MB) lives in /opt/venv/lib/python3.10/site-packages/. The dependencies include some heavyweights like scipy (84 MB) and pandas (56 MB). That seems right.

As the talk linked at the top shows, it's possible to make more progress if we're willing to accept much more complexity and longer build times. But as the talk recommends, something close to this approach is the pragmatic sweet spot.

@danielballan
Copy link
Member Author

Merging without further ado, as I want to use this as the base image for databroker.

@danielballan danielballan merged commit 73f1ad0 into bluesky:main Feb 1, 2023
@danielballan danielballan deleted the slimmer-image branch February 1, 2023 14:27
@danielballan
Copy link
Member Author

Released!

ghcr.io/bluesky/tiled      v0.1.0a82   d07b7256e137  6 minutes ago  823 MB

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

Successfully merging this pull request may close these issues.

1 participant