Skip to content

Prevent removing unexpected .a files in case of re-using the Dockerfile to build custom image - #706

Merged
tianon merged 3 commits into
docker-library:masterfrom
belltailjp:fix-removing-unexpected-dot-a-files
Mar 24, 2022
Merged

tianon merged 3 commits into
docker-library:masterfrom
belltailjp:fix-removing-unexpected-dot-a-files

Conversation

@belltailjp

Copy link
Copy Markdown
Contributor

Hello, I'd like to propose a slight change for cleaning up *.a which is defined here, so that it doesn't delete unexpected files.

-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \

Here is my background:
The current Dockerfile for the dockerhub Python image itself works pretty fine; it doesn't remove anything unexpected, even without my proposal.
However, since this official Dockerfile is so useful, clean and general, we often re-use (borrow) its content to make our own images on top of another image, typically by just rewriting the FROM section to something other.
For example, which is my actual case, we build a Python-ready image on top of nvidia/cuda:11.6.0-xxx. The issue here is that removing all the *.a under /usr/local as written in the current Dockerfile also destroys CUDA libraries. This combination is just an example but I think the same thing can happen in other patterns.

Looking at the actual files cleaned up here while building Python 3.10 images for slim-buster and alpine3.15, I found out /usr/local/lib/python3.10/config-3.10-x86_64-linux-gnu/libpython3.10.a is the only *.a file removed. So I think modifying the rule for the find command from '*.a' to 'libpython*.a' can prevent unexpectedly removing .a files of other libraries in case modifying FROM section, while it doesn't change anything on the image for dockerhub.

@tianon

tianon commented Mar 18, 2022

Copy link
Copy Markdown
Member

Interesting! I'm not opposed but I'd definitely like to do a more thorough check of other versions and variants just to be sure. 😅 🙈

(It'd be even cooler if we could find some way to convince Python not to build or install this file in the first place, but I'm not going to wish too hard for that one 😄)

@belltailjp

Copy link
Copy Markdown
Contributor Author

Thanks for the comment!

more thorough check of other versions and variants just to be sure

Sure! Then maybe I can proceed to run update.sh so you and anyone can test it.

@tianon
tianon force-pushed the fix-removing-unexpected-dot-a-files branch from 26ebe77 to 3b2ca12 Compare March 24, 2022 22:00
@tianon

tianon commented Mar 24, 2022

Copy link
Copy Markdown
Member

Nice, that was more successful than I expected. 😅 🤘

@tianon
tianon merged commit 0a9ee3e into docker-library:master Mar 24, 2022
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Mar 25, 2022
Changes:

- docker-library/python@0a9ee3e: Prevent removing unexpected .a files in case of re-using the Dockerfile to build custom image (docker-library/python#706)
docker-library-bot added a commit to docker-library-bot/official-images that referenced this pull request Apr 6, 2022
Changes:

- docker-library/python@37e4721: Update 3.11-rc to 3.11.0a7, pip 22.0.4
- docker-library/python@0a9ee3e: Prevent removing unexpected .a files in case of re-using the Dockerfile to build custom image (docker-library/python#706)
Omar290601 pushed a commit to Omar290601/python that referenced this pull request Aug 27, 2025
…le to build custom image (docker-library#706)

* Prevent removing unexpected .a files when building Python on top of other images

* Add a check in GitHub Actions for leftover ".a" files in "/usr/local"

Co-authored-by: Tianon Gravi <[email protected]>
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.

2 participants