I’m using nvidia/cudagl:11.4.2-base-ubuntu20.04, which does not include python. This is ok for me, since I need a very specific python version (3.9.9) anyhow. One way should be to compile python myself (e.g. according to https://askubuntu.com/a/890959). However, I thought maybe I could use a multi-stage build and just copy the required python executables from python:3.9.9-slim, so that I don’t have to deal with the compilation and its remnants.
Is that a feasible idea? And what exactly would need to be copied over?
2
Answers
As David Maze pointed out, it is apparently not a good idea to copy over a Python install. Unfortunately, the popular deadsnakes repository that he suggested, does not supply patch versions of Python, i.e. only the latest patch of Python 3.9 (at the time of writing 3.9.10) and not previous versions like 3.9.9.
I found that pyenv is a pretty convenient way to install a specific Python version (originally posted here):
It’s not really feasible to copy installed binaries from one image to another. If you know the application is only a static binary, or you know it has very controlled library dependencies, it could work, but Python installs things in many different directories and includes its own library tree. You’ll be much better off using the distribution package manager to install the specific version of Python you need.
Since your base image is based on Ubuntu, there’s an add-on Ubuntu repository that contains many different Python versions; also see Python 3.7 on Ubuntu 20.04. Translating that answer to Dockerfile format, you’d get something like:
As of this writing that includes Python 3.9.10 rather than 3.9.9, but this shouldn’t be a significant difference for you.