Need help getting access to NVIDIA GPU in newer Ubuntu containers. (Simple test case provided)

I am trying to get GPU acceleration using an Ubuntu 22.04 container.
I have come up with a very simple test case, see below

TLDR: I cannot figure out why the NVIDIA GPU is available in Ubuntu 20.04 and is not in Ubuntu 22.04

What simple thing am I missing?

**Assume I need to run in Ubuntu 22.04 **

Images I have tried that DO NOT give me the NVIDIA GPU:
ubuntu:jammy
ubuntu:22.04
nvidia/opengl:1.2-glvnd-runtime-ubuntu22.04
nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
nvidia/cuda:11.8.0-base-ubuntu22.04
ubuntu:24.04


Host Info:

Windows 11 Pro (24H2)

GeForce RTX 4080 / Driver 576.80

Docker version 28.3.0, build 38b7060
Docker Desktop 4.43.1

PowerShell> wsl --version
WSL version: 2.5.9.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.66
MSRDC version: 1.2.6074
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.4351


WSL Info/Setup

wsl@ubuntu> export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
wsl@ubuntu> nvidia-smi

Fri Jul 11 14:07:07 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 575.64.01              Driver Version: 576.80         CUDA Version: 12.9     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4080 ...    On  |   00000000:01:00.0  On |                  N/A |
| N/A   45C    P0             33W /  150W |     704MiB /  12282MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

wsl@ubuntu> glxinfo -B

name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Microsoft Corporation (0xffffffff)
    Device: D3D12 (NVIDIA GeForce RTX 4080 Laptop GPU) (0xffffffff)
    Version: 23.2.1
    Accelerated: yes
    Video memory: 44616MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 4.2
    Max compat profile version: 4.2
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 4080 Laptop GPU)
OpenGL core profile version string: 4.2 (Core Profile) Mesa 23.2.1-1ubuntu3.1~22.04.2
OpenGL core profile shading language version string: 4.20
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.2 (Compatibility Profile) Mesa 23.2.1-1ubuntu3.1~22.04.2
OpenGL shading language version string: 4.20
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.1 Mesa 23.2.1-1ubuntu3.1~22.04.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

wsl@ubuntu> glxinfo -B | grep “OpenGL renderer string”

OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 4080 Laptop GPU)    

In WSL my NVIDIA GPU is detected. All good so far.


While Docker Desktop is running and I am at a WSL console,

using Dockerfile:

FROM ubuntu:20.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install -y mesa-utils
ENV LD_LIBRARY_PATH=/usr/lib/wsl/lib

then build:

docker build -t hw_accel .

then run:

docker run -it --rm --gpus all --runtime=nvidia \
	-v /mnt/wslg:/mnt/wslg \
	-v /usr/lib/wsl:/usr/lib/wsl \
	-v /tmp/.X11-unix:/tmp/.X11-unix \
	-e DISPLAY=$DISPLAY \
	hw_accel bash

from inside ‘hw_accel’, the Ubuntu 20.04 container:

root@af071c43f1cf:/# cat /etc/os-release | grep PRETTY
PRETTY_NAME="Ubuntu 20.04.6 LTS"

root@af071c43f1cf:/# glxinfo -B | grep “OpenGL renderer string”
OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 4080 Laptop GPU)

root@3592eeab0256:/# glxgears -info | grep GL_RENDERER
GL_RENDERER = D3D12 (NVIDIA GeForce RTX 4080 Laptop GPU)

Container and glxgears are using the NVIDIA GPU. perfect!


Now if I go back the the Dockerfile and ONLY change the ubuntu version to 22.04

using UPDATED Dockerfile for 22.04:

FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install -y mesa-utils
ENV LD_LIBRARY_PATH=/usr/lib/wsl/lib

then build and run just like before

root@3592eeab0256:/# cat /etc/os-release | grep PRETTY
PRETTY_NAME="Ubuntu 22.04.5 LTS"

root@3592eeab0256:/# glxinfo -B | grep “OpenGL renderer string”
OpenGL renderer string: D3D12 (Intel(R) UHD Graphics)

root@3592eeab0256:/# glxgears -info | grep GL_RENDERER
GL_RENDERER = D3D12 (Intel(R) UHD Graphics)

Container and glxgears are using the INTEL in newer Ubuntu. Why???