This is a small guide to have NVIDIA accelerated OpenGL support for nvidia-docker2 on a HEADLESS Ubuntu 16.04/18.04 server.
sudo apt-get install xinit xserver-xorg-legacy mesa-utils xterm
sudo service gdm3 stop
sudo service lightdm stop
sudo sed -i -e "s/console/anybody/" /etc/X11/Xwrapper.config
Select OpenGL and driver install! Please also check that the driver fits the nvidia-docker driver volume!
sudo ./cuda10.0XXX.run
nvidia-xconfig --query-gpu-info
sudo nvidia-xconfig --busid=PCI:X:Y:Z --enable-all-gpus --use-display-device=none -o /etc/X11/xorg.conf
Section "DRI"
Mode 0666
EndSection
Check the correct BusID in the Device part
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:0:3:0"
EndSection
And then remove the option in the display part
Option "UseDisplayDevice" "none"
export DISPLAY=:0
xinit &
nvidia-smi
-> Check if Xorg is using nvidia driver under processes
glxinfo | grep OpenGL
If everything is ok there should be something with "NVIDIA OpenGL EGL"