apk:未找到,即使使用 python:3.9-alpine

apk: not found, even with python:3.9-alpine

我正在尝试构建 docker 图片:

FROM python:3.9-alpine

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
...

但是,我得到了这个错误:

Building app
Step 1/19 : FROM python:3.9-alpine
3.9-alpine: Pulling from library/python
df9b9388f04a: Pull complete
a1ef3e6b7a02: Pull complete
365abad9bce0: Pull complete
92eb277ed3c6: Pull complete
7b5fd7905244: Pull complete
Digest: sha256:602cd35ea12a7abc69078f447be06634700bdea7a2642712f8d21cfc35792df0
Status: Downloaded newer image for python:3.9-alpine
 ---> 9f14ea10b146
Step 2/19 : ENV PYTHONDONTWRITEBYTECODE=1
 ---> Running in dbf77cc82443
Removing intermediate container dbf77cc82443
 ---> 5686b41f46cf
Step 3/19 : ENV PYTHONUNBUFFERED=1
 ---> Running in fef9e4712712
Removing intermediate container fef9e4712712
 ---> 81bbdd0c12ca
Step 4/19 : ENV PATH="/scripts:{PATH}"
 ---> Running in bb1766c06644
Removing intermediate container bb1766c06644
 ---> 56c5312884d4
Step 5/19 : COPY ./Pipfile /Pipfile
 ---> 24cecd178fd0
Step 6/19 : COPY ./Pipfile.lock /Pipfile.lock
 ---> bfa1e72d5b1b
Step 7/19 : RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
 ---> Running in 8cb3f5f29a79
/bin/sh: apk: not found
ERROR: Service 'app' failed to build: The command '/bin/sh -c apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers' returned a non-zero code: 127

据我所知,最常见的问题是使用非 Alpine 图像并尝试访问 apk 管理器。但是,我不明白,我的怎么了。

我相信您必须在 docker 文件中添加运行时依赖项。尝试在您的 docker 文件

中添加此命令
FROM python:3.9-alpine

# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH

#add runtime dependencies
RUN apk add --no-cache

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

错误在这里

ENV PATH="/scripts:{PATH}"

改为

ENV PATH="/scripts:${PATH}"

你错过了一个$