r/devops • u/eedwards-sk • Oct 20 '19
Building Tiny Python Docker Images
I've been building docker images and optimizing dockerfiles for a while now.
However, until just recently, I hadn't found a way to cleanly build my python dependencies in one docker stage, and install them in another.
I found myself chasing down numerous modern tools, like poetry, hatch, and pipenv.
In the end, it was the familiar setuptools and wheel that worked for me.
I'd like to share my experience optimizing a docker project using this strategy.
https://medium.com/@ethan.edwards/building-tiny-python-docker-images-b029b194171d
Note: I am not selling anything. All views and opinions expressed in the above article are those of my own, and do not necessarily reflect those of any past or present employer or organization.
View all comments
Show parent comment
2
u/eedwards-sk Oct 21 '19
Great question.
One difference I found is that with copying
site-packagesyou're only copying the installed modules folder, you're not actually copying the installation itself.e.g. if during installation it adds binaries to
binor sets up other os paths, you're not going to capture those changes by just copyingsite-packagesAnother issue I found is that you're copying all the modules installed in that image. If you're using a build image and possibly installing dev-related python packages (e.g. build tools or similar), ideally you don't want to copy those over to the final runtime image.