Skip to content

Commit d762133

Browse files
committed
Simplify pip install step using ensurepip
Use ensurepip instead of fetching get-pip to install pip, to make the build step simpler. Note that --without-ensurepip in the Python configure args is still desired and correct, as it only prevents from running ensurepip after the build. The ensurepip and upgrade to the pinned version should be run in the same step to prevent layer bloat by modified files.
1 parent 10096f6 commit d762133

File tree

3 files changed

+12
-57
lines changed

3 files changed

+12
-57
lines changed

python/3.12/Dockerfile

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,7 @@ RUN \
112112
ARG PIP_VERSION
113113

114114
RUN set -ex; \
115-
\
116-
apk add --no-cache --virtual .fetch-deps openssl; \
117-
\
118-
curl -L -o get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
119-
\
120-
apk del .fetch-deps; \
121-
\
122-
python get-pip.py \
123-
--disable-pip-version-check \
124-
--no-cache-dir \
125-
pip==${PIP_VERSION} \
126-
; \
127-
pip --version; \
128-
\
129-
find /usr/local -depth \
130-
\( \
131-
-type d -a \( -name test -o -name tests \) \
132-
\) -exec rm -rf '{}' +; \
133-
rm -f get-pip.py
115+
python -m ensurepip --upgrade; \
116+
pip3 install --no-cache-dir --upgrade pip=="${PIP_VERSION}"; \
117+
ln -s /usr/local/bin/pip3 /usr/local/bin/pip; \
118+
pip --version

python/3.13/Dockerfile

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,7 @@ RUN \
112112
ARG PIP_VERSION
113113

114114
RUN set -ex; \
115-
\
116-
apk add --no-cache --virtual .fetch-deps openssl; \
117-
\
118-
curl -L -o get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
119-
\
120-
apk del .fetch-deps; \
121-
\
122-
python get-pip.py \
123-
--disable-pip-version-check \
124-
--no-cache-dir \
125-
pip==${PIP_VERSION} \
126-
; \
127-
pip --version; \
128-
\
129-
find /usr/local -depth \
130-
\( \
131-
-type d -a \( -name test -o -name tests \) \
132-
\) -exec rm -rf '{}' +; \
133-
rm -f get-pip.py
115+
python -m ensurepip --upgrade; \
116+
pip3 install --no-cache-dir --upgrade pip=="${PIP_VERSION}"; \
117+
ln -s /usr/local/bin/pip3 /usr/local/bin/pip; \
118+
pip --version

python/3.14/Dockerfile

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,7 @@ RUN \
113113
ARG PIP_VERSION
114114

115115
RUN set -ex; \
116-
\
117-
apk add --no-cache --virtual .fetch-deps openssl; \
118-
\
119-
curl -L -o get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
120-
\
121-
apk del .fetch-deps; \
122-
\
123-
python get-pip.py \
124-
--disable-pip-version-check \
125-
--no-cache-dir \
126-
pip==${PIP_VERSION} \
127-
; \
128-
pip --version; \
129-
\
130-
find /usr/local -depth \
131-
\( \
132-
-type d -a \( -name test -o -name tests \) \
133-
\) -exec rm -rf '{}' +; \
134-
rm -f get-pip.py
116+
python -m ensurepip --upgrade; \
117+
pip3 install --no-cache-dir --upgrade pip=="${PIP_VERSION}"; \
118+
ln -s /usr/local/bin/pip3 /usr/local/bin/pip; \
119+
pip --version

0 commit comments

Comments
 (0)