2

Specifically in this base image https://hub.docker.com/r/frolvlad/alpine-glibc/ how does one add Python 3.8 to it.. Adding python3 installs Python3.6.9. Went through How do I install python on alpine linux? but couldn't figure it out.

  • Have you tried using `python38` instead of `python3` ? – Chance Feb 13 '21 at 00:18
  • Yeah, tried 38 and 3.8 results in this error: ```ERROR: unsatisfiable constraints: python38 (missing): required by: world[python38] The command '/bin/sh -c apk add --update python38' returned a non-zero code: 1``` – Vikash Raja Samuel Selvin Feb 13 '21 at 00:20
  • Hmm. https://hub.docker.com/_/python lists `3.8-alpine` as a tag that exists, and links to the Dockerfile at https://github.com/docker-library/python/blob/e8674e6765191491bd69161c41c89e37acb8b9f2/3.8/alpine3.13/Dockerfile . Maybe something there will help you? – Chance Feb 13 '21 at 00:43
  • 1
    You probably have an old version or old tag of this `alpine-glibc` image because on the latest version, they go `FROM alpine:3.13` which will install a Python 3.8. What version or tag of the glibc image ore you using? – β.εηοιτ.βε Feb 13 '21 at 13:32
  • That said, alpine tends to have a package of the dependencies per version, if the package manager does not have the version you want and you cannot afford to upgrade your alpine version, you're left with installing what you want from sources. – β.εηοιτ.βε Feb 13 '21 at 13:33

2 Answers2

2

Another solution, use official Python Docker image and COPY:

FROM python:3.8.13-alpine3.16 as python

COPY --from=python /usr/local/bin/python3 /usr/local/bin/python3
COPY --from=python /usr/local/lib/python3.8 /usr/local/lib/python3.8
COPY --from=python /usr/local/lib/libpython3.8.so.1.0 /usr/local/lib/libpython3.8.so.1.0
COPY --from=python /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so
Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
1

In the time of writing, the latest frolvlad/alpine-glibc image is based on Alpine 3.13.2. The current Python 3 version for Alpine 3.13 is 3.8.8. Therefore, for installing Python 3.8 simply install the python3 package. This is also true for Alpine 3.12 and 3.11.

If you're using frolvlad/alpine-glibc based on Alpine 3.13, 3.12 or 3.11, try updating the apk database with apk update followed by apk add python3.

On images based on older Alpine versions, such as Alpine 3.9, you'll not be able to install a functional Python 3.8, since it depends on musl 1.1.24 which is only available starting Alpine 3.10. Even though it could be installed using the Alpine 3.11+ repositories, it will fail to run due to the said musl dependency:

/ # apk add python3=3.8.2-r2 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.11/main
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
(1/10) Installing libbz2 (1.0.8-r1)
(2/10) Installing expat (2.2.9-r1)
(3/10) Installing libffi (3.2.1-r6)
(4/10) Installing gdbm (1.13-r1)
(5/10) Installing xz-libs (5.2.4-r0)
(6/10) Installing ncurses-terminfo-base (6.1_p20200118-r4)
(7/10) Installing ncurses-libs (6.1_p20200118-r4)
(8/10) Installing readline (8.0.1-r0)
(9/10) Installing sqlite-libs (3.30.1-r2)
(10/10) Installing python3 (3.8.2-r2)
Executing busybox-1.29.3-r10.trigger
Executing glibc-bin-2.29-r0.trigger
OK: 71 MiB in 27 packages
/ # python3 --version
Error relocating /usr/lib/libpython3.8.so.1.0: copy_file_range: symbol not found
valiano
  • 16,433
  • 7
  • 64
  • 79