ubuntu store system python package in /usr/lib/python3/dist-packages and share it for all python3 versions.

Inside an ubuntu 20.04 container (docker run -ti ubuntu:20.04):

apt-get update
apt-get install software-properties-common
add-apt-repository ppa:deadsnakes/ppa
# Install py39 from deadsnakes repository
apt-get install python3.9
# Install pip from standard ubuntu packages
apt-get install python3-pip

Then you can invoke pip with python3.9 -m pip ..., but be careful, everything with be installed in /usr/lib/python3/dist-packages.

But if all you need is a dockerized version of python3.9, it would be better to use the official python docker image, available with debian or alpine (very light) as a base. Both use a standard lib/pythonx.y/site-packages.

By default these images defines entrypoint to the python interpreter, but you can override why bash or busybox sh (alpine).

Edit for debian

launchpad repositories are build on ubuntu distribution. Using on over distribution can lead in libraries incompatibilities.

In deadsnakes ubuntu/xenial repository, python3.9 requires libssl1.0.0, but debian/buster offer libssl1.1.

The easiest way to get python3.9 in debian / buster is to use the official image (docker run -ti python:3.9-buster). Otherwise, build it ...

Answer from Balaïtous on Stack Overflow
🌐
Docker Hub
hub.docker.com › _ › python
python - Official Image | Docker Hub
3.14.4-windowsservercore-ltsc2022, 3.14-windowsservercore-ltsc2022, 3-windowsservercore-ltsc2022, windowsservercore-ltsc2022⁠ ... Supported architectures: (more info⁠) amd64⁠, arm32v5⁠, arm32v6⁠, arm32v7⁠, arm64v8⁠, i386⁠, ppc64le⁠, riscv64⁠, s390x⁠, windows-amd64⁠ · Published image artifact details: repo-info repo's repos/python/ directory⁠ (history⁠) (image metadata, transfer size, etc)
🌐
Medium
medium.com › @prateek.mehra › installing-python-3-9-in-ubuntu-22-04-docker-image-194f9c9f9725
Installing Python 3.9 in Ubuntu 22.04 docker image | by Prateek Mehra | Medium
July 2, 2024 - Installing Python 3.9 in Ubuntu 22.04 docker image The Problem On trying to install Python 3.9 in a fresh ubuntu 22.04 docker image, using the following command: apt-get install -y python3.9 The …
Find elsewhere
🌐
Red Hat
catalog.redhat.com › en › software › containers › rhel9 › python-39 › 61a6101fbfd4a5234d59629d
Python 3.9 - Red Hat Ecosystem Catalog
February 24, 2026 - To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: FROM registry.fedoraproject.org/f33/python3 # Add application sources to a directory that the assemble script expects them # and set permissions so that the container runs without root access USER 0 ADD app-src /tmp/src RUN /usr/bin/fix-permissions /tmp/src USER 1001 # Install the dependencies RUN /usr/libexec/s2i/assemble # Set the default command for the resulting image CMD /usr/libexec/s2i/run
🌐
GitHub
github.com › docker-library › python
GitHub - docker-library/python: Docker Official Image packaging for Python · GitHub
This is the Git repo of the Docker "Official Image" for python (not to be confused with any official python image provided by python upstream).
Starred by 2.7K users
Forked by 1.1K users
Languages   Dockerfile 50.3% | Shell 49.7%
🌐
Stack Overflow
stackoverflow.com › questions › 74797619 › python-3-9-supported-for-docker-images
amazon web services - Python 3.9 Supported for Docker images? - Stack Overflow
Yes. There's an official python:3.9 image you can use. 3.11 is the latest official image. ... Look at the official Docker Hub Python image.
🌐
Python⇒Speed
pythonspeed.com › articles › base-image-python-docker-images
The best Docker base image for your Python application (February 2026)
February 4, 2026 - Older versions, which you probably ... RHEL 9 and Debian 12, and as mentioned soon Ubuntu 24.04 will be superseded. You can get long term security updates for older distributions, but that’s a bad idea; better to upgrade more often. They may also not have security updates for all packages, as is the case for Debian long-term support. Another alternative is Docker’s own “official” python image, which comes pre-installed with respective versions of Python (3.10, 3.11, ...
🌐
Medium
luis-sena.medium.com › creating-the-perfect-python-dockerfile-51bdec41f1c8
Creating the Perfect Python Dockerfile | by Luis Sena | Medium
September 20, 2021 - Using a remote image as a cache is especially useful for your CI build where a cache folder might not be available and you would have cold builds for every pipeline. ... # syntax=docker/dockerfile:1.2 FROM ubuntu:20.04 RUN apt-get update && apt-get install -y python3.9 python3.9-dev COPY requirements.txt .RUN --mount=type=cache,mode=0755,target=/root/.cache pip install -r requirements.txtCOPY .
🌐
GitHub
github.com › snakepacker › python
GitHub - snakepacker/python: Python docker images · GitHub
C compiler and developer tools FROM ghcr.io/snakepacker/python:all as builder # Create virtualenv on python 3.10 # Target folder should be the same on the build stage and on the target stage RUN python3.10 -m venv /usr/share/python3/app # Install target package RUN /usr/share/python3/app/bin/pip install -U pip 'ipython[notebook]' # Will be find required system libraries and their packages RUN find-libdeps /usr/share/python3/app > /usr/share/python3/app/pkgdeps.txt ################################################################# ####################### TARGET STAGE ############################
Starred by 78 users
Forked by 17 users
Languages   Dockerfile 84.7% | Makefile 8.5% | Python 5.5% | Shell 1.3%