Skip to content

Commit 71d3309

Browse files
authored
Merge pull request docker-library#139 from infosiftr/templatize
Add a few simple Python 3 templates based on existing Dockerfiles
2 parents 3f51e91 + f1bc9f7 commit 71d3309

26 files changed

+786
-199
lines changed

2.7/Dockerfile

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
FROM buildpack-deps:jessie
22

3-
# ensure local python is used over debian python
3+
# ensure local python is preferred over distribution python
44
ENV PATH /usr/local/bin:$PATH
55

66
# http://bugs.python.org/issue19846
77
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
88
ENV LANG C.UTF-8
99

10-
# gpg: key 18ADD4FF: public key "Benjamin Peterson <benjamin@python.org>" imported
11-
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
10+
# runtime dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
tcl \
13+
tk \
14+
&& rm -rf /var/lib/apt/lists/*
1215

16+
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1317
ENV PYTHON_VERSION 2.7.12
1418

1519
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
@@ -20,13 +24,10 @@ RUN set -ex \
2024
tcl-dev \
2125
tk-dev \
2226
' \
23-
&& runDeps=' \
24-
tcl \
25-
tk \
26-
' \
27-
&& apt-get update && apt-get install -y $runDeps $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
28-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
29-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
27+
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
28+
\
29+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
30+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
3031
&& export GNUPGHOME="$(mktemp -d)" \
3132
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
3233
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
@@ -42,9 +43,13 @@ RUN set -ex \
4243
&& make -j$(nproc) \
4344
&& make install \
4445
&& ldconfig \
45-
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
46-
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
47-
&& [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
46+
\
47+
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
48+
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
49+
&& rm /tmp/get-pip.py \
50+
&& pip install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
51+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
52+
\
4853
&& find /usr/local -depth \
4954
\( \
5055
\( -type d -a -name test -o -name tests \) \

2.7/alpine/Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM alpine:3.4
22

3+
# ensure local python is preferred over distribution python
4+
ENV PATH /usr/local/bin:$PATH
5+
36
# http://bugs.python.org/issue19846
47
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
58
ENV LANG C.UTF-8
@@ -8,18 +11,21 @@ ENV LANG C.UTF-8
811
# the other runtime dependencies for Python are installed later
912
RUN apk add --no-cache ca-certificates
1013

11-
# gpg: key 18ADD4FF: public key "Benjamin Peterson <benjamin@python.org>" imported
1214
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
13-
1415
ENV PYTHON_VERSION 2.7.12
1516

1617
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
1718
ENV PYTHON_PIP_VERSION 8.1.2
1819

1920
RUN set -ex \
20-
&& apk add --no-cache --virtual .fetch-deps curl gnupg tar xz \
21-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
22-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
21+
&& apk add --no-cache --virtual .fetch-deps \
22+
gnupg \
23+
openssl \
24+
tar \
25+
xz \
26+
\
27+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
28+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
2329
&& export GNUPGHOME="$(mktemp -d)" \
2430
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
2531
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
@@ -35,6 +41,7 @@ RUN set -ex \
3541
linux-headers \
3642
make \
3743
ncurses-dev \
44+
openssl \
3845
openssl-dev \
3946
pax-utils \
4047
readline-dev \
@@ -43,15 +50,22 @@ RUN set -ex \
4350
tk \
4451
tk-dev \
4552
zlib-dev \
53+
# add build deps before removing fetch deps in case there's overlap
54+
&& apk del .fetch-deps \
55+
\
4656
&& cd /usr/src/python \
4757
&& ./configure \
4858
--enable-shared \
4959
--enable-unicode=ucs4 \
5060
&& make -j$(getconf _NPROCESSORS_ONLN) \
5161
&& make install \
52-
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
53-
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
54-
&& [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
62+
\
63+
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
64+
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
65+
&& rm /tmp/get-pip.py \
66+
&& pip install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
67+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
68+
\
5569
&& find /usr/local -depth \
5670
\( \
5771
\( -type d -a -name test -o -name tests \) \
@@ -66,7 +80,7 @@ RUN set -ex \
6680
| sort -u \
6781
)" \
6882
&& apk add --virtual .python-rundeps $runDeps \
69-
&& apk del .build-deps .fetch-deps \
83+
&& apk del .build-deps \
7084
&& rm -rf /usr/src/python ~/.cache
7185

7286
CMD ["python2"]

2.7/slim/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
FROM debian:jessie
22

3-
# ensure local python is used over debian python
3+
# ensure local python is preferred over distribution python
44
ENV PATH /usr/local/bin:$PATH
55

66
# http://bugs.python.org/issue19846
77
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
88
ENV LANG C.UTF-8
99

10+
# runtime dependencies
1011
RUN apt-get update && apt-get install -y --no-install-recommends \
1112
ca-certificates \
1213
libsqlite3-0 \
1314
libssl1.0.0 \
1415
&& rm -rf /var/lib/apt/lists/*
1516

16-
# gpg: key 18ADD4FF: public key "Benjamin Peterson <benjamin@python.org>" imported
1717
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
18-
1918
ENV PYTHON_VERSION 2.7.12
2019

2120
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
2221
ENV PYTHON_PIP_VERSION 8.1.2
2322

2423
RUN set -ex \
2524
&& buildDeps=' \
26-
curl \
2725
gcc \
2826
libbz2-dev \
2927
libc6-dev \
@@ -34,12 +32,14 @@ RUN set -ex \
3432
make \
3533
tcl-dev \
3634
tk-dev \
35+
wget \
3736
xz-utils \
3837
zlib1g-dev \
3938
' \
4039
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
41-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
42-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
40+
\
41+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
42+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
4343
&& export GNUPGHOME="$(mktemp -d)" \
4444
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
4545
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
@@ -55,9 +55,13 @@ RUN set -ex \
5555
&& make -j$(nproc) \
5656
&& make install \
5757
&& ldconfig \
58-
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
59-
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
60-
&& [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
58+
\
59+
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
60+
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
61+
&& rm /tmp/get-pip.py \
62+
&& pip install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
63+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
64+
\
6165
&& find /usr/local -depth \
6266
\( \
6367
\( -type d -a -name test -o -name tests \) \

2.7/wheezy/Dockerfile

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
FROM buildpack-deps:wheezy
22

3-
# ensure local python is used over debian python
3+
# ensure local python is preferred over distribution python
44
ENV PATH /usr/local/bin:$PATH
55

66
# http://bugs.python.org/issue19846
77
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
88
ENV LANG C.UTF-8
99

10-
# gpg: key 18ADD4FF: public key "Benjamin Peterson <benjamin@python.org>" imported
11-
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
10+
# runtime dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
tcl \
13+
tk \
14+
&& rm -rf /var/lib/apt/lists/*
1215

16+
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1317
ENV PYTHON_VERSION 2.7.12
1418

1519
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
@@ -20,13 +24,10 @@ RUN set -ex \
2024
tcl-dev \
2125
tk-dev \
2226
' \
23-
&& runDeps=' \
24-
tcl \
25-
tk \
26-
' \
27-
&& apt-get update && apt-get install -y $runDeps $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
28-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
29-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
27+
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
28+
\
29+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
30+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
3031
&& export GNUPGHOME="$(mktemp -d)" \
3132
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
3233
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
@@ -42,9 +43,13 @@ RUN set -ex \
4243
&& make -j$(nproc) \
4344
&& make install \
4445
&& ldconfig \
45-
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python2 \
46-
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
47-
&& [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
46+
\
47+
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
48+
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
49+
&& rm /tmp/get-pip.py \
50+
&& pip install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
51+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
52+
\
4853
&& find /usr/local -depth \
4954
\( \
5055
\( -type d -a -name test -o -name tests \) \

3.3/Dockerfile

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
17
FROM buildpack-deps:jessie
28

3-
# ensure local python is used over debian python
9+
# ensure local python is preferred over distribution python
410
ENV PATH /usr/local/bin:$PATH
511

612
# http://bugs.python.org/issue19846
713
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
814
ENV LANG C.UTF-8
915

10-
# gpg: key 36580288: public key "Georg Brandl (Python release signing key) <georg@python.org>" imported
11-
ENV GPG_KEY 26DEA9D4613391EF3E25C9FF0A5B101836580288
16+
# runtime dependencies
17+
RUN apt-get update && apt-get install -y --no-install-recommends \
18+
tcl \
19+
tk \
20+
&& rm -rf /var/lib/apt/lists/*
1221

22+
ENV GPG_KEY 26DEA9D4613391EF3E25C9FF0A5B101836580288
1323
ENV PYTHON_VERSION 3.3.6
1424

1525
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
@@ -20,13 +30,10 @@ RUN set -ex \
2030
tcl-dev \
2131
tk-dev \
2232
' \
23-
&& runDeps=' \
24-
tcl \
25-
tk \
26-
' \
27-
&& apt-get update && apt-get install -y $runDeps $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
28-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
29-
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
33+
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
34+
\
35+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
36+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
3037
&& export GNUPGHOME="$(mktemp -d)" \
3138
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
3239
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
@@ -42,9 +49,16 @@ RUN set -ex \
4249
&& make -j$(nproc) \
4350
&& make install \
4451
&& ldconfig \
45-
&& curl -fSL 'https://bootstrap.pypa.io/get-pip.py' | python3 \
46-
&& pip install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
47-
&& [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
52+
\
53+
# explicit path to "pip3" to ensure distribution-provided "pip3" cannot interfere
54+
&& if [ ! -e /usr/local/bin/pip3 ]; then : \
55+
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
56+
&& python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
57+
&& rm /tmp/get-pip.py \
58+
; fi \
59+
&& pip3 install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
60+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
61+
\
4862
&& find /usr/local -depth \
4963
\( \
5064
\( -type d -a -name test -o -name tests \) \
@@ -56,6 +70,7 @@ RUN set -ex \
5670

5771
# make some useful symlinks that are expected to exist
5872
RUN cd /usr/local/bin \
73+
&& { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
5974
&& ln -s idle3 idle \
6075
&& ln -s pydoc3 pydoc \
6176
&& ln -s python3 python \

0 commit comments

Comments
 (0)