I'm trying to run OpenGL applications (Gazebo) inside a Ubuntu 16.04 container, and I'd like to be able to take advantage of nvidia graphics acceleration when available. I'm trying to figure out what the recommended, officially supported (by nvidia, hopefully) way to achieve this is.
My requirements:
- Creating the image is time-consuming, so I'd like to either have one image for all kinds of graphics (nvidia, mesa i.e. everything else), or if separate, they should be built "FROM" a common base image with the bulk of the content.
- The nvidia container should work on different systems which may have different nvidia cards and driver versions installed.
- I need to use Ubuntu 16.04, company requires this, although this is the least-important of these requirements, e.g. if this could only be done on 18.04 I'd be interested as well.
What I've tried so far:
- Just build separate images for nvidia and everything else, with
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04
. This works well, but requires to build two images, which takes twice the time and twice the disk space. Breaks requirement 1. - Build the "normal" (mesa/intel) image first from
ubuntu:16.04
, do all the time-consuming stuff there, then use this as the base for another image where NVIDIA drivers are installed manually from the official "run file". This works if the driver matches exactly the driver installed on the host, but not if the host has a different (e.g. older) version. Breaks requirement 2. - Do nothing, just run my regular mesa-enabled container with
--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all
. If I do,nvidia-smi
sees the card, but OpenGL (e.g.glxinfo
) still tries to load theswrast
driver, which doesn't work.
Most examples I've seen in the wild use the nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04
base, and for the life of me I cannot find how the nvidia drivers are installed (if at all) in that image. I've also read somewhere that with the nvidia container runtime (i.e. nvidia-docker2
, which I'm using) you don't need to install the drivers, but that doesn't seem to be the case, at least not for OpenGL.
So again, is there a way to create container images for nvidia and non-nvidia that satisfy all my requirements, or do I just want too much?