Skip to content

Conversation

@autoferrit
Copy link
Contributor

This is based on #448 by @lubo

I ran this locally with the change and it worked out well. I build the 3.8-alpine3.11 image (tagging it as just py3 here) and the image size went from 107MB to 78.9MB, a reduction in size of ~26%

❯ docker images REPOSITORY TAG IMAGE ID CREATED SIZE py3 latest 95f26289fc0e 4 minutes ago 78.9MB python 3.8-alpine3.11 6c32e2504283 2 weeks ago 107MB

@autoferritautoferrit mentioned this pull request May 13, 2020
@yosifkit
Copy link
Member

For future reference, this saves ~20 MB on every Alpine based image.

We want to leave the debuggability in the regular Debian images, but we should add this to the slim images which gets similar 20-30 MB savings. Do you want to update the PR to include them?

diff --git a/Dockerfile-slim.template b/Dockerfile-slim.template index 3d0c359..457f865 100644 --- a/Dockerfile-slim.template+++ b/Dockerfile-slim.template@@ -65,6 +65,7 @@ RUN set -ex \ --with-system-ffi \ --without-ensurepip \ && make -j "$(nproc)" \ + LDFLAGS="-Wl,--strip-all" \ # setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916 PROFILE_TASK='-m test.regrtest --pgo \ test_array \

@autoferrit
Copy link
ContributorAuthor

Done

Copy link
Member

@yosifkityosifkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@yosifkityosifkit requested a review from tianonMay 15, 2020 20:23
@tianon
Copy link
Member

(Rebased to remove unrelated version bumps -- I plan to merge once CI says we're green 👍)

Thanks!

@tianon
Copy link
Member

Those last two jobs look stuck -- I'm merging anyhow. 👍

@tianontianon merged commit f83ecbf into docker-library:masterMay 19, 2020
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request May 19, 2020
Changes: - docker-library/python@f83ecbf: Merge pull request docker-library/python#483 from autoferrit/master - docker-library/python@6a981eb: also should apply to slim images. - docker-library/python@7dc395a: add LDFLAGS for optimizing image size
Omar290601 pushed a commit to Omar290601/python that referenced this pull request Aug 27, 2025
Since docker-library#687, the regular Debian images no longer ship DWARF symbols, which heavily limits the ability to use gdb and lldb for debugging. Stripping debugging symbols makes perfect sense to reduce the size of Docker images, but when this optimization was first introduced in docker-library#483, the idea was to restrict its use to the slim and Alpine images. That was (unintentionally?) changed in docker-library#483, and now debugging symbols are also stripped in the regular Debian images. Undo that change.
Sign up for freeto 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.

3 participants

@autoferrit@yosifkit@tianon