Creating an up-to-date Distroless Python Image (2022)
alexos.dev
alexos.dev
I do something similar for my personal containers.
I have a common Ubuntu base image, that I add a bunch of tools to, which I might need for debugging later and install apt updates to as a part of the build process and remove the apt cache (so instead of changing the base image all the time to a more recent one, I still have an up to date container, at the expense of some additional layers).
Then, on top of that base image I have other specialized images, ones with Apache, some with JDK, some for .NET, Python, Node, Ruby etc., which I can then build my apps upon, while having a few useful tools in the container, as well as a bunch of shared layers that the nodes will be able to reuse.
The only exceptions are images like PostgreSQL, MariaDB, SeaweedFS etc., which I just take from Docker Hub, usually the Bitnami variety: https://bitnami.com/stacks/containers because I almost never need to connect to those or use them as base images, but rather just use them as connected services.
Should enterprises do that? Probably not. It is, however, an immensely pleasant approach to things, that lets me not stress about optimization and just use what works for me.
If this were that easy, chroot with PID isolation alone would be quite enough.
https://www.bnikolic.co.uk/blog/python/nix/2023/03/23/nixpyd...
the issue of people not documenting their dependencies is not addressed by nix, other than the fact that undocumented dependencies also won't "works on my machine", until it's resolved.
Here is a full example: https://github.com/cogini/phoenix_container_example/blob/mai...
https://hub.docker.com/r/stagex/python/tags
They are as bare as it gets: https://codeberg.org/stagex/stagex/src/branch/main/packages/...
Literally just Python. Import hash-locked musl, openssl, etc as needed (also provided by stagex), for a reproducible and tiny final Python project container image.
Never seen a stability issue. Speed can be a problem with the stock malloc but you are free to include scudo, jemalloc, or any malloc you want.
You also are free to include glibc at the last mile and link your final binary against that.
You can configure Bazel to fetch a standalone Python interpreter. Your app is bundled with the right interpreter for the target platform. rules_pycross can fetch the correct dependencies across platforms. Bazel can put this into a minimalist base image.
I haven’t come across anything else that fixes this for Python. The conventional wisdom is to give up and build in Docker.
Details: https://jpetazzo.github.io/2015/01/13/docker-mount-dynamic-v...
Shipping debug tools, a package manager, or even a shell in a production container is increasing attack surface and image size for no reason.
Do not ship dev tooling to prod. Pull and attach it on demand only. Servers and containers should be immutable appliances.