I have the following multi stage build to add pyrender into a 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
If I run pyrender inside debian:11-slim
it works all well but when I move the libraries to distroless and try to run import pyrender
I get
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)
or
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)
I did set the env variable to os.environ['PYOPENGL_PLATFORM'] = 'egl'
Any pointers on what I'm doing wrong? I would like to run it with distroless and not the debian image.
Adding these fixed my issues,
Although
/usr/bin
added a bunch of stuff that I don't need to be baked in the final image. however, I do not know which exact executable is needed in the bunch. If anyone knows please comment. For now this solves my issue without massively bloating the final image.