在 Docker 中运行 GLFW

在 Docker 中运行 GLFW

我有一个用 Go 编写的简单程序,它使用 GLFW 打开一个空白窗口。我想自动运行测试,因此我一直在尝试让 GLFW 在 docker 中运行。到目前为止,我已经成功地让 xvfb 运行起来。

GLX extension not found我的问题是调用时出现错误glfwInit。另外,运行glxinfo会产生此错误couldn't find RGB GLX visual or fbconfig。从我在网上可以找到的情况来看,这是因为 GLFW 找不到 GPU(因为没有)。

是否还需要安装一个库或者我可以配置不同的东西吗(例如在无头模式下运行 GLFW)以防止这个错误?

这是我的 Dockerfile 的缩短版本(删除了 Go 特定的内容):

FROM alpine:latest

RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add glibc-2.28-r0.apk

RUN apk update
RUN apk add gcc
RUN apk add mesa-dev
RUN apk add libx11-dev
RUN apk add libc-dev
RUN apk add libx11-dev
RUN apk add libxcursor-dev
RUN apk add libxi-dev
RUN apk add libxinerama-dev
RUN apk add libxrandr-dev
RUN apk add xorg-server
RUN apk add xvfb
RUN apk add coreutils
RUN apk add mesa
RUN apk add mesa-gl
RUN apk add mesa-demos
RUN apk add xvfb-run --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ --allow-untrusted
RUN apk add mesa-osmesa

#if you are unfamiliar with docker, this is the command that gets run when starting the container.
ENTRYPOINT xvfb-run -e /dev/stderr --server-args=':99 -screen 0 640x480x8 +extension GLX +render -noreset -ac' glxinfo | cat

输出:

The XKEYBOARD keymap compiler (xkbcomp) reports:
> Warning:          Unsupported high keycode 372 for name <I372> ignored
>                   X11 cannot support keycodes above 255.
>                   This warning only shows for the first high keycode.
Errors from xkbcomp are not fatal to the X server
name of display: :99
Error: couldn't find RGB GLX visual or fbconfig

我认为 XKEYBOARD 警告并不重要,可以忽略。

答案1

事实证明,mesa-dri-gallium缺少启用 GLX 扩展的软件包。

完成的 Dockerfile 如下所示:

FROM alpine:edge

RUN apk update

# Dependencies for GLFW (not required for this example)
RUN apk add \
    build-base \
    libx11-dev \ 
    libxcursor-dev \
    libxrandr-dev \
    libxinerama-dev \
    libxi-dev \
    mesa-dev

# Required to run xvfb-run
RUN apk add mesa-dri-gallium xvfb-run

# virtualgl includes glxinfo
RUN apk add virtualgl --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted

ENTRYPOINT xvfb-run -e /dev/stderr glxinfo | cat

相关内容