Use NVIDIA GPU with WSL Docker
Table of Contents
Prerequisites
- Install WSL2 and Ubuntu 22.04 to Windows (see my previous post)
- Install Docker to WSL (see my previous post)
Install NVIDIA Driver to Windows
Install NVIDIA driver to Windows (see NVIDIA Driver Downloads):
Install NVIDIA Container Toolkit to WSL
Install NVIDIA Container Toolkit to WSL (see Installing the NVIDIA Container Toolkit - NVIDIA):
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
# Restart docker
sudo systemctl restart docker
Configure docker:
sudo nvidia-ctk runtime configure --runtime=docker
# Restart docker
sudo systemctl restart docker
Test NVIDIA GPU with Docker
Test NVIDIA GPU with Docker with cuda image (see nvidia/cuda - Dockerhub):
docker run --rm --gpus all nvidia/cuda:12.8.0-cudnn-runtime-ubuntu22.04 nvidia-smi