0

我有以下多阶段构建将 pyrender 添加到 distroless continer

FROM debian:11-slim as build
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
    apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev \
    wget git ca-certificates python python3-pip libglu1-mesa-dev freeglut3-dev && \
    python3 -m venv /venv && \
    /venv/bin/pip install --upgrade pip setuptools wheel

RUN /venv/bin/pip install pyrender pyopengl PyOpenGL_accelerate

FROM gcr.io/distroless/python3-debian11

COPY --from=build /usr/lib /usr/lib
COPY --from=build /usr/include /usr/include
COPY --from=build /venv /venv

如果我在里面运行 pyrenderdebian:11-slim它一切正常但是当我将库移动到 distroless 并尝试运行时import pyrender我得到

File "/venv/lib/python3.9/site-packages/OpenGL/platform/glx.py", line 20, in GL
    raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'GL: cannot open shared object file: No such file or directory', 'GL', None)

或者

File "/venv/lib/python3.9/site-packages/pyrender/platforms/egl.py", line 83, in get_device_by_index
    raise ValueError('Invalid device ID ({})'.format(device_id, len(devices)))
ValueError: Invalid device ID (0)

我确实将环境变量设置为os.environ['PYOPENGL_PLATFORM'] = 'egl'

关于我做错了什么的任何指示?我想用 distroless 而不是 debian 映像运行它。

4

1 回答 1

0

添加这些解决了我的问题,

COPY --from=build /usr/bin /usr/bin
COPY --from=build /usr/lib /usr/lib
COPY --from=build /usr/share /usr/share
COPY --from=build /usr/local /usr/local

虽然/usr/bin添加了一堆我不需要在最终图像中烘焙的东西。但是,我不知道这堆中需要哪个确切的可执行文件。如果有人知道请发表评论。现在,这解决了我的问题,而不会使最终图像大量膨胀。

于 2022-02-20T20:05:08.040 回答