add LDFLAGS for optimizing image size#483
Merged
tianon merged 2 commits intodocker-library:masterfrom May 19, 2020
Merged
Conversation
Closed
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 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 \ |
Contributor
Author
|
Done |
Member
|
(Rebased to remove unrelated version bumps -- I plan to merge once CI says we're green 👍) Thanks! |
Member
|
Those last two jobs look stuck -- I'm merging anyhow. 👍 |
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
This was referenced Feb 5, 2022
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.11image (tagging it as justpy3here) and the image size went from 107MB to 78.9MB, a reduction in size of ~26%