简体   繁体   English

来自python:3.x-alpine3.x的Alpine Docker映像使用的Python软件包版本与声明的软件包版本不同

[英]Alpine Docker image FROM python:3.x-alpine3.x uses different package version for Python than stated

If I build the simpliest docker image based on Alpine that includes Python: 如果我基于包含Python的Alpine构建最简单的docker映像:

FROM python:3.7-alpine3.9

I can successfully enter it and verify that the installed version is 3.7: 我可以成功输入它并验证安装的版本是3.7:

/ # python --version
Python 3.7.3
/ # python3 --version
Python 3.7.3

However if I install some packages that require Python3, for example python3-dev (that is required by other packages) or Python3 itself, Alpine does not use version 3.7 but uses 3.6 for some reason that I don't understand: 但是,如果我安装了一些需要Python3的软件包,例如python3-dev (其他软件包需要此软件包)或Python3本身,则Alpine不使用3.7版,但出于某些我不理解的原因而使用3.6版:

/ # apk add python3-dev
(1/3) Installing pkgconf (1.6.0-r0)
(2/3) Installing python3 (3.6.8-r2)
(3/3) Installing python3-dev (3.6.8-r2)
Executing busybox-1.29.3-r10.trigger
OK: 108 MiB in 38 packages

printenv also shows that (during the docker image build) version 3.7.x is used but package system does not reflect this. printenv还显示(在docker映像构建期间)使用了3.7.x版,但软件包系统未反映出这一点。 Excerpt: 摘抄:

PYTHON_VERSION=3.7.3

I see here there's Python 3.6 as a default version for all Alpine versions up to 3.9. 在这里看到Python 3.6是所有最高3.9的Alpine版本的默认版本。 Python 3.7 is available for the "edge" only. Python 3.7仅可用于“边缘”。

I also found answer to this which doesn't work either: 我也找到了对此无效的答案:

# apk add python3 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
(1/1) Installing python3 (3.6.8-r2)

Python 3.6 is installed. 已安装Python 3.6。 However if I use the simpliest Alpine without Python FROM alpine:3.9 and use the same command, Python 3.7 is installed : 但是,如果我使用最简单的Alpine而没有Python FROM alpine:3.9并使用相同的命令, 则会安装Python 3.7

# apk add python3 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
<TRIMMED_TEXT>
(11/11) Installing python3 (3.7.3-r0)

How can I tell the package manager in python:3.7-alpine3.9 to use Python 3.7 instead of Python 3.6? 如何告诉python:3.7-alpine3.9的软件包管理器使用Python 3.7而不是Python 3.6?

If you remove the ( virtual ) .python-rundeps package beforehand, the installation will work as you intend it. 如果您事先删除了( virtual.python-rundeps软件包,则安装将按.python-rundeps

FROM python:3.7-alpine3.9

RUN \
    apk update \
    && apk del .python-rundeps \
    && apk add --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main \
        python3-dev=3.7.3-r0

Building this image results in: 构建此图像将导致:

...
(12/13) Installing python3 (3.7.3-r0)
...

Do you need python version 3.7? 您是否需要python版本3.7? You can use version 3.6, It exists: https://hub.docker.com/_/python/?tab=tags&page=3 您可以使用3.6版本,该版本存在: https://hub.docker.com/_/python/?tab=tags&page=3 : https://hub.docker.com/_/python/?tab=tags&page=3

FROM python:3.6-alpine3.9

or 要么

FROM python:3.6.8-alpine
FROM python:3.6-alpine
FROM python:3.6.8-alpine3.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM