Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pythoninthegrass/891b7ff86dd0661337723d4ea8d5a566 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/891b7ff86dd0661337723d4ea8d5a566 to your computer and use it in GitHub Desktop.
Dockerfile to build a specific version of Python and set it as the default using Deadsnakes
# syntax=docker/dockerfile:1.7
FROM ubuntu:20.04
ARG PYTHON_VERSION="3.11"
ENV TZ=US/Chicago
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
#!/usr/bin/env bash
apt-get update -qq
apt-get install -qq --no-install-recommends -y \
software-properties-common
add-apt-repository ppa:deadsnakes/ppa -y
apt-get update -qq
apt-get install -qq --no-install-recommends -y \
python3-pip \
python3.11 \
python3.11-venv
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF
RUN update-alternatives --install \
/usr/bin/python3 python /usr/bin/python${PYTHON_VERSION} 1 \
&& update-alternatives --set python /usr/bin/python${PYTHON_VERSION} \
&& update-alternatives --set python /usr/bin/python${PYTHON_VERSION}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment