Skip to content

Hardware acceleration

mviereck edited this page Jul 31, 2019 · 14 revisions

Hardware accelerated graphics with GPU access for docker container

x11docker allows hardware acceleration for docker containers with option --gpu. This wiki page gives some insights to allow custom setups without x11docker.

Groups video and render

If you run with an unprivileged user in container, add him to groups video and render to allow access to the files in /dev/dri:

--group-add video --group-add render

Hardware acceleration with open source drivers (MESA)

Share /dev/dri

GPU devices on linux are stored in /dev/dri. The most simple setup to allow hardware acceleration is to share these device files with docker run option --device /dev/dri.

This works flawlessly with open source drivers (MESA) on host and in image.

Share /dev/vga_arbiter

Additionally it can make sense to share /dev/vga_arbiter, too, as it may be needed for some multimonitor setups. Use docker run option --device /dev/vga_arbiter.

Install open source drivers in image

  • Debian and Ubuntu images: mesa-utils mesa-utils-extra
  • CentOS and Fedora images: glx-utils mesa-dri-drivers
  • Alpine and NixOS images: mesa-demos mesa-dri-ati mesa-dri-intel mesa-dri-nouveau mesa-dri-swrast
  • Arch Linux images: mesa-demos

Hardware acceleration with closed source driver (NVIDIA)

The free driver for NVIDIA graphics cards is nouveau. With nouveau driver follow instructions above, it will work out of the box with MESA setups.

Closed source non-free proprietary nvidia-driver needs a quite customized and non-portable setup.

To ease things, x11docker allows automated install of nvidia driver in containers. Follow instructions given by x11docker terminal output or look at x11docker wiki: NVIDIA driver.

For a setup without automated install by x11docker, you need to install the driver matching your host driver version in image. The image will not be portable anymore.

Install NVIDIA driver in image

Share /dev/nvidia* with container

Share all files matching /dev/nvidia* with docker run option --device. Share /dev/dri and /dev/vga_arbiter, too.

Clone this wiki locally