如何从主机到dockerimagr传递有关GPU(OpenGL,Op​​enCL,mesa等版本)的数据/信息?

我目前正在运行的Ubuntu 16.04.2,相当新的安装只是足够的开始编程。 我有一个r9 390 AMD卡,这个问题和AMD的驱动有很多问题,但我不认为这是个问题。

我用下面的代码创build了一个dockerfile:

FROM ubuntu:16.04 ..... ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y --no-install-recommends apt-utils WORKDIR /buildls CMD ["bash"] RUN apt-get install -y x11-apps RUN apt-get install -y libcanberra-gtk* RUN apt-get -y install libglfw3-dev RUN apt-get -y install libglew-dev RUN apt-get -y install mesa-utils ....... 

build立后,我运行它:

 docker run -it `#container process` \ -v /tmp/.X11-unix:/tmp/.X11-unix `#Allows the X11 server to be shared (GUI)` \ -v $(pwd)/volume:/app `#Shares a folder, one down in current directory (~/volume) with ROOT/app in the container` \ -e DISPLAY=$DISPLAY `#Shares the display between the 2 systems` \ opengl_why_you_no_work \ 

我创build了一个简单的GL loader程序,使用GLFW和GLEW,我做了2个版本来支持OpenGL 2.1(你会明白为什么会在后面)和3.2。 在我编写的示例程序(带有一些debugging输出调用)和

  glxinfo|grep OpenGL 

我有一些有趣的问题。 在我的主机上使用glxinfo调用,我得到了

 OpenGL vendor string: X.Org OpenGL renderer string: Gallium 0.4 on AMD HAWAII (DRM 2.46.0 / 4.8.0-58-generic, LLVM 3.8.0) OpenGL core profile version string: 4.1 (Core Profile) Mesa 12.0.6 OpenGL core profile shading language version string: 4.10 OpenGL version string: 3.0 Mesa 12.0.6 OpenGL shading language version string: 1.30 OpenGL ES profile version string: OpenGL ES 3.0 Mesa 12.0.6 OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00 

在docker上的图像:

 OpenGL vendor string: VMware, Inc. OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.8, 256 bits) OpenGL core profile version string: 3.3 (Core Profile) Mesa 12.0.6 OpenGL core profile shading language version string: 3.30 OpenGL version string: 3.0 Mesa 12.0.6 OpenGL shading language version string: 1.30 OpenGL ES profile version string: OpenGL ES 3.0 Mesa 12.0.6 OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00 

嗯,供应商? 所以,为OpenGL 2.1编写的程序,使用:

 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); 

在主机和docker上运行; 简单的渲染…但它的作品。 即使它在docker上的图像呈现,我仍然得到这个错误:

 libGL error: failed to open drm device: Permission denied libGL error: failed to load driver: radeonsi 

如果我尝试运行在Docker镜像上为OpenGL 3.2创build的版本,则不会显示任何渲染,也不会显示窗口,上面提供了相同的2个错误,并且此输出为:

 Renderer: (null) OpenGL version supported (null) 

代替docker镜像上的2.1版本:

 Renderer: Gallium 0.4 on llvmpipe (LLVM 3.8, 256 bits) OpenGL version supported 3.0 Mesa 12.0.6 

或者在主机上运行任一版本的结果:

 Renderer: Gallium 0.4 on AMD HAWAII (DRM 2.46.0 / 4.8.0-58-generic, LLVM 3.8.0) OpenGL version supported 4.1 (Core Profile) Mesa 12.0.6 

所以,我认为这与X.org和VMware,Inc.的供应商有关。我可以重写,传递,replace或以其他方式解决此问题吗? 我可能可以编写OpenGL 3.0的代码(在那里很有趣),但是一旦我在程序中变得更复杂,libGL错误就会让我担心。 此外,我想尝试OpenCL,我相信我会有类似的问题。

我find了答案,但它可能会杀了一些…但它的作品!

我添加到Dockerfile中:

 RUN apt-get install -y xserver-xorg-video-all RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ libgl1-mesa-dri \ && rm -rf /var/lib/apt/lists/* .... RUN usermod -a -G video <username> 

但是,我认为mesa文件已经在那里作为结果

 FROM ubuntu:16.04 

线。 我还补充说:

 --device=/dev/dri:/dev/dri 

到脚本运行泊坞窗图像。 有趣的是,当我正在排除故障时,我将MESA升级到最新版本(17.1这里 – > http://www.omgubuntu.co.uk/2017/05/mesa-17-1-ubuntu-ppa ),现在我在我的主机上安装了GL 4.5,在图像上安装了MESA 12.0.6 4.1当然,现在我将需要研究如何使它在Windows / OS主机上可执行。

我使用了以下参考:

机器人操作系统(ROS)的第303页:完整参考,第2卷(谷歌预览)

bbs.archlinux.org/viewtopic.php?id=175164

github.com/hilbert/hilbert-docker-images/issues/9

stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container

askubuntu.com/questions/809081/how-to-run-opencl-program-in-docker-container-with-amdgpu-pro