我正在尝试使用 gcr.io./distroless/python3-debian10 使用基本映像作为 debian:buster-slim 创建一个无发行版容器
我已经在基础镜像的 python 虚拟环境中安装了 enchant,然后我将虚拟环境复制到了 distroless 镜像,但是附魔库文件没有被复制到 distroless 容器中。
在调试时我发现,附魔已正确安装在基础映像容器中并且工作正常,但它没有反映在 distroless 容器中。
这是错误消息:
Traceback (most recent call last):
File "app.py", line 17, in <module>
import utils as utils
File "/app/utils.py", line 13, in <module>
import enchant
File "/venv/lib/python3.7/site-packages/enchant/__init__.py", line 81, in <module>
from enchant import _enchant as _e
File "/venv/lib/python3.7/site-packages/enchant/_enchant.py", line 157, in <module>
raise ImportError(msg)
ImportError: The 'enchant' C library was not found and maybe needs to be installed.
See https://pyenchant.github.io/pyenchant/install.html
for details
我从错误消息中转到了这个建议的 url(https://pyenchant.github.io/pyenchant/install.html),因为他们已经指定安装已经安装的 pyenchant。而且我还安装了 libenchant,附魔。
这是供参考的代码:
FROM debian:buster-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip
RUN apt-get update -y
WORKDIR /venv/
RUN apt-get install libre2-dev git wget vim python3-enchant libenchant-dev -y
RUN apt-get install libre2-5
RUN apt-get install enchant -y
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt
FROM gcr.io/distroless/python3-debian10
COPY --from=build-venv /venv /venv
COPY . /app
WORKDIR /app
EXPOSE 6000
ENTRYPOINT ["/venv/bin/python3", "app.py"]
注意:我在 requirements.txt 文件中包含了 pyenchant(version :3.2.1)