UNCLASSIFIED - NO CUI

Question about final image size

I'm using the python38 image for development and recently notice that this image is based of the RedHat UBI 8 but the size difference between python38 and the ubi is significant. At this time these are the sizes I'm seeing after pulling from registry1.dso.mil:

REPOSITORY                                                TAG         IMAGE ID       CREATED          SIZE
registry1.dso.mil/ironbank/redhat/ubi/ubi8                latest      270a1a2fa210   48 minutes ago   244MB
registry1.dso.mil/ironbank/opensource/python/python38     latest      599bae66ebd2   9 days ago       733MB

It seems like the Dockerfile does a best effort to remove dnf/build leftovers but it doesn't seem like Python should be taking up ~500 mb of image space. To compare this with python 3.8 on Docker Hub the sizes are as follows

python 3.8 buster        -- 332.99 MB
python 3.8 slim-buster   -- 42.2 MB

I understand that the Docker hub version is using Alpine Linux, but still the delta between ubi and the python38 is larger than the entire python:3.8-buster. From a casual inspection it looks like they are taking care to delete the following interim build files:

  • *.pyc
  • *.pyo
  • *.a

https://github.com/docker-library/python/blob/e0e01b8482ea14352c710134329cdd93ece88317/3.8/buster/Dockerfile#L54

Perhaps by updating the Dockerfile or including a .dockeringore to exclude these kinds of files we can improve things?

Here's an example .dockerignore file from k8s... https://github.com/GoogleCloudPlatform/getting-started-python/blob/main/optional-kubernetes-engine/.dockerignore

Thanks!!!

Edited by Kent McHenry