running nvidia-docker on Windows 10 WSL2
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Running GPU-accelerated Docker containers on Windows requires WSL2, the NVIDIA GPU driver for WSL, and Docker Desktop with WSL2 backend enabled. The nvidia-docker runtime is not needed on WSL2 — the NVIDIA Container Toolkit integrates directly through Docker's --gpus flag. The GPU driver is installed on Windows only (not inside WSL), and Docker Desktop routes GPU access through WSL2's Linux kernel to your containers.
Prerequisites
- Windows 10 Build 21H2 or later (or Windows 11)
- WSL2 enabled with a Linux distribution (Ubuntu recommended)
- NVIDIA GPU with CUDA support (GTX 1060+ / RTX series / Tesla)
- NVIDIA GPU driver 510.06+ installed on Windows (includes WSL2 support)
- Docker Desktop 4.x with WSL2 backend enabled
Step 1: Install WSL2
Step 2: Install NVIDIA GPU Driver (Windows Side Only)
Download and install the NVIDIA GPU driver from nvidia.com/drivers. The driver version must be 510.06 or higher — these include built-in WSL2 support. Do NOT install CUDA or GPU drivers inside the WSL2 distribution; the Windows driver handles everything.
Step 3: Configure Docker Desktop
- Open Docker Desktop Settings
- General: Enable "Use the WSL 2 based engine"
- Resources > WSL Integration: Enable integration for your Ubuntu distribution
- Apply and restart Docker Desktop
Step 4: Run GPU Containers
Docker Compose with GPU
Installing NVIDIA Container Toolkit (Alternative to Docker Desktop)
If you use the Docker Engine inside WSL2 directly (without Docker Desktop), install the NVIDIA Container Toolkit:
Troubleshooting
Common Pitfalls
- Installing NVIDIA drivers inside WSL2: The GPU driver must be installed on Windows only. WSL2 uses the Windows driver through a special kernel interface. Installing a Linux NVIDIA driver inside WSL2 conflicts with the passthrough driver and breaks GPU access. If you did this, uninstall the Linux driver with
sudo apt remove --purge nvidia-*. - Using
nvidia-dockerornvidia-docker2package on WSL2: The legacynvidia-dockerwrapper is deprecated. On WSL2, usedocker run --gpus alldirectly. The NVIDIA Container Toolkit handles GPU passthrough through Docker's native--gpusflag without needing a separate runtime wrapper. - CUDA version mismatch between driver and container: The container's CUDA version must be less than or equal to the driver's CUDA version. Running
nvidia/cuda:12.2.0-baseon a driver that supports CUDA 11.8 fails. Check your driver's CUDA version withnvidia-smiand use matching container tags. - Docker Desktop WSL integration not enabled for the right distribution: Docker Desktop must have WSL integration enabled for the specific distribution you are using. Go to Settings > Resources > WSL Integration and toggle on your Ubuntu distribution. Without this,
dockercommands inside WSL2 fail with "command not found." - WSL2 kernel too old for GPU support: GPU passthrough requires WSL2 kernel 5.10.43.3 or later. Run
uname -rinside WSL2 to check. Update withwsl --updatefrom PowerShell if the kernel is outdated. Older kernels do not have the/dev/dxgdevice needed for GPU access.
Summary
- Install the NVIDIA GPU driver on Windows only (510.06+), never inside WSL2
- Enable WSL2 backend in Docker Desktop and turn on integration for your distribution
- Use
docker run --gpus allto pass GPUs into containers — nonvidia-dockerneeded - Match container CUDA versions to your driver's maximum supported CUDA version
- Use
nvidia-smiboth inside WSL2 and inside containers to verify GPU access at each layer
Related reading
- Running tf.mod and tf.floor_div in tensorflow in GPU
- RuntimeError Attempting to deserialize object on a CUDA device
- RuntimeError Expected 4-dimensional input for 4-dimensional weight 32 3 3, but got 3-dimensional input of size 3, 224, 224 instead?
- RuntimeError Input type torch.FloatTensor and weight type torch.cuda.FloatTensor should be the same
- SASL authentication in docker zookeeper and kafka
- Scalable spring batch job on kubernetes
- RuntimeError tf.placeholder is not compatible with eager execution
- RuntimeError Unable to create link name already exists Keras

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.