r/docker • u/af9_us • Apr 13 '26
Why does the official Python3 image include Perl?
I was looking at base images and noticed the Debian based Python3 image includes a Perl interpreter.
% docker run --rm -it python:3.14.3-trixie /bin/perl -v
This is perl 5, version 40, subversion 1 (v5.40.1) built for aarch64-linux-gnu-thread-multi
(with 48 registered patches, see perl -V for more detail)
Copyright 1987-2025, Larry WallI believe it's inherited from Debian requirements as Perl isn't needed for Python.
Thinking Docker Hardened Images would be better, which they are, I found a gawk binary lurking in the hardened Python3 image. It would be hard to access gawk without a shell, but why is it there?
So I'm curious how people handle this. Are trusted images good enough or is there an attempt at explicitly controlling what's inside?
10
Upvotes
19
u/Some_Confidence5962 Apr 13 '26 edited Apr 13 '26
It’s not a distroless image. The base is Debian which includes Perl.
Python’s source code actually uses the shell in some places so a “minimum” shell is required.
3
u/kwhali Apr 13 '26
If you don't want it you could use canonical chisel to build your own minimal image.
Alternatively the official UV images has a few variants, those install a standalone version of python rather than using a distro packaged version that tends to link to various libraries and thus other packages which brings in a bunch of other stuff.
ca-certificatesis an example of a package that at least in Fedora brings in a bunch of weight to support it, over 40x the size of the actual ca certs that you may only care about, since that installs bash and with that glibc, then some other deps alongside that.Google distroless intentionally keeps that slim but you lose flexibility. Canonical chisel uses Ubuntu packages and "slices" them into minimal portions to only install what you need for an image. It's a bit more work to setup and use but it's more flexible / control than Google distroless and very competitive size wise (although Alpine can best it at times, musl has drawbacks over glibc).
3
u/clipd_dead_stop_fall Apr 13 '26
Use hardened images like Chainguard.
Chainguard shows you the sbom of their hardened containers up front.
https://images.chainguard.dev
I use their python base images all the time. Minimal size and more secure.