I want to use debian:bullseye
as a base image and then install a specific Python version – i.e. 3.11.1. At the moment I am just learning docker and linux.
From what I understand I can either:
- Download and compile sources
- Install binaries (using apt-get)
- Use a Python base image
I have come across countless questions on here and articles online. Do I use deadsnakes? What version do I need? Are there any official python distributions (who is deadsnakes anyway)?
But ultimately I want to know the best means of getting Python on there. I don’t want to use a Python base image – I am curious in the steps involved. Compile sources – I am far from having that level of knowhow – and one for another day.
Currently I am rolling with the following:
FROM debian:bullseye
RUN apt update && apt upgrade -y
RUN apt install software-properties-common -y
RUN add-apt-repository "ppa:deadsnakes/ppa"
RUN apt install python3.11
This fails with:
#8 1.546 E: Unable to locate package python3.11
#8 1.546 E: Couldn't find any package by glob 'python3.11'
Ultimately – it’s not the error – its just finding a good way of getting a specific Python version on my container.
2
Answers
In case you want to install Python 3.11 in debian bullseye you have to compile it from source following the next steps (inside the Dockerfile):
Another option (easiest) would be to use the official Python Docker image, in your case:
You have all the versions available in docker hub.
Other option that could be interesting in your case is
3.11-slim-bullseye
, that is an image that does not contain the common packages contained in the default tag and only contains the minimal packages needed to run python.Based on @tomasborella answer, to do this in docker:
Dockerfile
update-alternatives
– will update the links to allow you to runpython
as opposed to specifyingpython3.11
when you want to run it.It takes a while to compile those sources!