-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add LDFLAGS for optimizing image size #483
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
Conversation
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 \ |
Done |
There was a problem hiding this 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.
(Rebased to remove unrelated version bumps -- I plan to merge once CI says we're green 👍) Thanks! |
Those last two jobs look stuck -- I'm merging anyhow. 👍 |
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
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 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 justpy3
here) and the image size went from 107MB to 78.9MB, a reduction in size of ~26%