Docker
在 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 警告並不重要,可能會被忽略。
事實證明,
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