Skip to content

Hardware acceleration

mviereck edited this page Oct 21, 2020 · 14 revisions

GPU access for docker containers

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

  • Note that only two X servers support GPU acceleration: Xorg and Xwayland. Others like Xephyr, nxagent or Xvfb only support software rendering.
  • Wayland compositors like weston support GPU acceleration even in nested window mode.

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.

For use of x11docker with proprietary nvidia driver look at x11docker wiki: NVIDIA driver.

For a setup without x11docker, you have two possibilities:

Share NVIDIA device files with container

To use a custom base image, share all files matching /dev/nvidia*, /dev/nvhost* and /dev/nvmap with docker run option --device. Share /dev/dri and /dev/vga_arbiter, too. Add container user to groups video and render with --group-add video --group-add render.

Clone this wiki locally