How to install python specific version on docker?

Question:

I need to install python 3.8.10 in a container running ubuntu 16.04.

16.04 has no support anymore, so I need a way to install it there manually.

Asked By: Gulzar

||

Answers:

This follows from here

Add the following to your dockerfile, and change the python version as needed.

When the docker is up, python3.8 will be available in /usr/local/bin/python3.8

# compile python from source - avoid unsupported library problems
RUN apt update -y && sudo apt upgrade -y && 
    apt-get install -y wget build-essential checkinstall  libreadline-gplv2-dev  libncursesw5-dev  libssl-dev  libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && 
    cd /usr/src && 
    sudo wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz && 
    sudo tar xzf Python-3.8.10.tgz && 
    cd Python-3.8.10 && 
    sudo ./configure --enable-optimizations && 
    sudo make altinstall

Please note the following (standard [and quicker] way of installing) does not work for old ubuntu versions, due to end of support

RUN apt-get update && 
    apt-get install -y software-properties-common && 
    add-apt-repository -y ppa:deadsnakes/ppa && 
    apt-get update && 
    apt install -y python3.8

See also this to install into /usr/bin

Answered By: Gulzar