1+ FROM buildpack-deps:bookworm
2+
3+ LABEL \
4+ maintainer="César Román <cesar@coatl.dev>" \
5+ repository="https://github.com/coatl-dev/docker-python" \
6+ vendor="coatl.dev"
7+
8+ ENV DEBIAN_FRONTEND=noninteractive
9+
10+ ENV PIP_NO_CACHE_DIR=1
11+ ENV PIP_ROOT_USER_ACTION=ignore
12+
13+ # ensure local python is preferred over distribution python
14+ ENV PATH=/usr/local/bin:$PATH
15+
16+ # runtime dependencies
17+ RUN set -eux; \
18+ apt-get update; \
19+ apt-get upgrade --yes; \
20+ apt-get install -y --no-install-recommends \
21+ libbluetooth-dev \
22+ tk-dev \
23+ uuid-dev \
24+ ; \
25+ rm -rf /var/lib/apt/lists/*
26+
27+ ENV PYTHON_VERSION=3.14.0
28+
29+ RUN set -eux; \
30+ \
31+ wget -q -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" ; \
32+ mkdir -p /usr/src/python; \
33+ tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
34+ rm python.tar.xz; \
35+ \
36+ cd /usr/src/python; \
37+ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" ; \
38+ ./configure \
39+ --build="$gnuArch" \
40+ --enable-loadable-sqlite-extensions \
41+ --enable-optimizations \
42+ --enable-option-checking=fatal \
43+ --enable-shared \
44+ --with-lto \
45+ --without-ensurepip \
46+ ; \
47+ nproc="$(nproc)" ; \
48+ EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)" ; \
49+ LDFLAGS="$(dpkg-buildflags --get LDFLAGS)" ; \
50+ EXTRA_CFLAGS="${EXTRA_CFLAGS:-} -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" ; \
51+ make -j "$nproc" \
52+ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
53+ "LDFLAGS=${LDFLAGS:-}" \
54+ ; \
55+ # https://github.com/docker-library/python/issues/784
56+ # prevent accidental usage of a system installed libpython of the same version
57+ rm python; \
58+ make -j "$nproc" \
59+ "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
60+ "LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ ORIGIN/../lib'" \
61+ python \
62+ ; \
63+ make install; \
64+ \
65+ # enable GDB to load debugging data: https://github.com/docker-library/python/pull/701
66+ bin="$(readlink -ve /usr/local/bin/python3)" ; \
67+ dir="$(dirname " $bin")" ; \
68+ mkdir -p "/usr/share/gdb/auto-load/$dir" ; \
69+ cp -vL Tools/gdb/libpython.py "/usr/share/gdb/auto-load/$bin-gdb.py" ; \
70+ \
71+ cd /; \
72+ rm -rf /usr/src/python; \
73+ \
74+ find /usr/local -depth \
75+ \( \
76+ \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
77+ -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
78+ \) -exec rm -rf '{}' + \
79+ ; \
80+ \
81+ ldconfig; \
82+ \
83+ export PYTHONDONTWRITEBYTECODE=1; \
84+ python3 --version
85+
86+ # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends)
87+ SHELL ["/bin/bash" , "-o" , "pipefail" , "-c" ]
88+ RUN set -eux; \
89+ for src in idle3 pydoc3 python3 python3-config; do \
90+ dst="$(echo " $src" | tr -d 3)" ; \
91+ [ -s "/usr/local/bin/$src" ]; \
92+ [ ! -e "/usr/local/bin/$dst" ]; \
93+ ln -svT "$src" "/usr/local/bin/$dst" ; \
94+ done
95+
96+ # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
97+ ENV PYTHON_PIP_VERSION=25.2
98+ # https://github.com/pypa/get-pip
99+ ENV PYTHON_GET_PIP_URL=https://raw.githubusercontent.com/pypa/get-pip/HEAD/public/get-pip.py
100+
101+ RUN set -eux; \
102+ \
103+ wget -q -O get-pip.py "$PYTHON_GET_PIP_URL" ; \
104+ \
105+ export PYTHONDONTWRITEBYTECODE=1; \
106+ \
107+ python get-pip.py \
108+ --disable-pip-version-check \
109+ --no-compile \
110+ "pip==$PYTHON_PIP_VERSION" \
111+ --no-setuptools \
112+ --no-wheel \
113+ ; \
114+ rm -f get-pip.py; \
115+ \
116+ pip --version
117+
118+ CMD ["python3" ]
0 commit comments