Modern applications increasingly depend on GPU computing. Artificial intelligence, machine learning, image processing, video encoding, scientific simulations, and data analytics can perform computationally intensive operations that benefit from GPU acceleration.
Developers working on Windows can use NVIDIA GPUs inside Linux containers without installing a separate Linux operating system. Docker Desktop, Windows Subsystem for Linux 2 (WSL 2), and NVIDIA GPU Paravirtualization make this possible.
However, installing Docker Desktop and running a container does not automatically provide GPU access. Windows, the NVIDIA driver, WSL 2, Docker Desktop, and the container runtime must work together.
Docker Desktop supports NVIDIA GPU acceleration for Linux containers through its WSL 2 backend. It uses GPU Paravirtualization (GPU-PV) to make the host GPU available to applications running inside the Linux environment.
In this article, we will configure NVIDIA GPU support on Windows, connect Docker Desktop with WSL 2, run CUDA-enabled containers, execute a GPU computation example, and troubleshoot common GPU access problems.
1. Understand How NVIDIA GPU Containers Work on Windows
A traditional Linux server can run Docker directly on the Linux kernel. Windows requires an additional layer because Linux containers need a Linux environment.
WSL 2 solves this problem by providing a real Linux kernel running in a lightweight virtual machine.
Docker Desktop uses this environment to run Linux containers.
When an application inside a container requests GPU access, Docker and WSL 2 provide a path to the physical NVIDIA GPU through GPU Paravirtualization.
The architecture looks like this:
Windows 11
|
v
NVIDIA Windows Driver
|
v
WSL 2 Kernel
|
v
GPU Paravirtualization
|
v
Docker Desktop
|
v
Docker Engine
|
v
Linux Container
|
v
CUDA Application
|
v
NVIDIA GPU
The important point is that the NVIDIA driver is installed on Windows.
WSL 2 exposes the GPU functionality to the Linux environment. Docker then makes the GPU available to supported Linux containers.
This allows developers to use CUDA-enabled applications without installing a separate NVIDIA Linux kernel driver inside their WSL distribution.
What Is GPU Paravirtualization?
GPU Paravirtualization, or GPU-PV, allows a virtualized environment to access GPU resources provided by the host system.
Instead of passing an entire physical GPU directly to a virtual machine, the virtualization layer exposes supported GPU capabilities to the guest environment.
In this case:
Windows owns the physical NVIDIA GPU.
The Windows NVIDIA driver provides GPU support.
WSL 2 exposes GPU functionality to Linux applications.
Docker passes the available GPU devices to containers.
CUDA applications execute GPU operations.
This approach is useful for developers who want Linux-based AI and machine learning environments while continuing to use Windows as their primary operating system.
2. Understand the Requirements
Before configuring Docker, verify that your computer meets the requirements.
Component | Requirement |
|---|
Operating system | Supported Windows 10 or Windows 11 version |
GPU | NVIDIA GPU |
GPU driver | Current NVIDIA driver with WSL 2 GPU support |
Virtualization | Hardware virtualization enabled |
WSL | WSL 2 with an updated Linux kernel |
Docker Desktop | Current version supporting GPU passthrough |
Docker backend | WSL 2 |
Container type | Linux containers |
GPU framework | Compatible CUDA-enabled application |
Docker Desktop's GPU passthrough feature for Linux containers is supported with NVIDIA GPUs through the WSL 2 backend.
It is important to distinguish this from other Docker Desktop virtualization backends. The standard --gpus passthrough workflow is not supported through Docker VMM or the Hyper-V backend.
Check Your NVIDIA GPU
Open PowerShell and run:
nvidia-smi
If the NVIDIA driver is installed correctly, the command displays information such as:
For example, the output may show an NVIDIA GeForce RTX or NVIDIA RTX workstation GPU.
If PowerShell cannot recognize the command, install or update the appropriate NVIDIA Windows driver before continuing.
The CUDA version displayed by nvidia-smi represents the maximum CUDA version supported by the installed driver. It does not necessarily mean that the CUDA Toolkit is installed.
3. Install and Configure WSL 2
WSL 2 provides the Linux environment required by Docker Desktop.
Open PowerShell as Administrator.
Install WSL:
wsl --install
This installs WSL and the default Linux distribution when the required Windows features are available.
Restart Windows if requested.
Update WSL
GPU support depends on a compatible WSL kernel.
Run:
wsl --update
Check the installed version:
wsl --version
Check available Linux distributions:
wsl --list --verbose
Example output:
NAME STATE VERSION
Ubuntu Running 2
docker-desktop Running 2
The important value is VERSION 2.
If an installed Linux distribution is running under WSL 1, convert it:
wsl --set-version Ubuntu 2
You can also configure WSL 2 as the default for new distributions:
wsl --set-default-version 2
Why Is an Updated WSL Kernel Important?
WSL 2 provides the Linux kernel functionality needed to expose GPU resources.
Older WSL kernels and outdated Windows GPU drivers can cause problems such as:
CUDA applications failing to detect a GPU.
Containers reporting that no compatible GPU is available.
GPU initialization errors.
CUDA runtime failures.
Updating WSL before configuring Docker reduces the likelihood of these problems.
4. Install the NVIDIA Windows Driver
The NVIDIA Windows driver is responsible for providing GPU functionality to both Windows applications and supported WSL 2 workloads.
Download the appropriate driver from NVIDIA.
Choose the driver based on your GPU model and operating system.
Install the driver and restart Windows if required.
After installation, open PowerShell:
nvidia-smi
Verify that the GPU is detected.
Important: Do Not Install a Linux NVIDIA Display Driver Inside WSL
This is an important configuration detail.
When using NVIDIA GPU support through WSL 2, the Windows NVIDIA driver provides the GPU functionality.
WSL exposes the required driver interface through its Linux environment.
Installing a separate Linux NVIDIA kernel driver inside WSL can cause conflicts with this setup.
For CUDA development, install the required CUDA Toolkit components only when your development workflow needs them. Follow NVIDIA's WSL-specific installation instructions rather than installing a generic Linux GPU driver.
5. Verify NVIDIA GPU Access Inside WSL 2
Before configuring Docker, verify that WSL itself can access the GPU.
Start your Linux distribution:
wsl
Inside Ubuntu, run:
nvidia-smi
If GPU support is working, the command should display the NVIDIA GPU information.
You can also check the NVIDIA device interface:
ls -l /dev/dxg
The /dev/dxg device provides the interface used by WSL applications to access GPU functionality through the Windows graphics virtualization infrastructure.
If nvidia-smi works inside WSL, it is a good indication that the Windows driver and WSL GPU integration are configured correctly.
However, Docker still needs to be configured separately.
6. Configure Docker Desktop to Use WSL 2
Install Docker Desktop for Windows using the official Docker installer.
During installation, select the WSL 2 backend when prompted.
After installation, start Docker Desktop.
Open:
Docker Desktop
|
v
Settings
|
v
General
|
v
Use the WSL 2 based engine
Enable the WSL 2 based engine if it is not already enabled.
Select Apply and restart.
Enable WSL Integration
Open Docker Desktop settings:
Settings
|
v
Resources
|
v
WSL Integration
Enable integration for your Linux distribution, such as Ubuntu.
Select Apply.
This allows developers to execute Docker commands directly from the WSL terminal.
For example:
docker version
Check that both the client and server information are displayed.
Verify Docker Engine:
docker info
If the Docker server information appears correctly, the WSL distribution can communicate with Docker Desktop.
Confirm Linux Container Mode
Docker GPU passthrough through --gpus requires Linux containers.
If Docker Desktop is running in Windows container mode, switch to Linux containers using the Docker Desktop interface.
This distinction matters because the CUDA examples in this article use Linux container images.
7. Run Your First NVIDIA GPU Container
Now that Windows, WSL 2, and Docker Desktop are configured, test GPU access from a container.
Docker supports the --gpus option for requesting GPU devices.
Run:
docker run --rm \
--gpus all \
nvidia/cuda:12.6.3-base-ubuntu22.04 \
nvidia-smi
The command performs several operations:
docker run starts a new container.
--rm removes the container after it exits.
--gpus all requests access to all available GPUs.
nvidia/cuda selects an NVIDIA CUDA container image.
nvidia-smi checks GPU availability from inside the container.
The output should contain the NVIDIA GPU information.
For example:
+--------------------------------------------------------------+
| NVIDIA-SMI |
+--------------------------------------------------------------+
| GPU Name Persistence-M |
| NVIDIA GeForce RTX Off |
| |
| Memory Usage GPU Utilization |
| 1024MiB / 8192MiB 0% |
+--------------------------------------------------------------+
The displayed GPU model and memory values depend on your hardware.
This is the first important validation step: the container can see the GPU.
If the command succeeds, Docker GPU passthrough is working at a basic level.
8. Understand the Docker GPU Configuration
Docker provides several options for controlling which GPU resources a container can access.
Access All Available GPUs
docker run --rm \
--gpus all \
nvidia/cuda:12.6.3-base-ubuntu22.04 \
nvidia-smi
This requests all GPUs available to Docker.
Access a Specific GPU
If the system has multiple supported GPUs, you can select one by index.
docker run --rm \
--gpus '"device=0"' \
nvidia/cuda:12.6.3-base-ubuntu22.04 \
nvidia-smi
This requests GPU index 0.
Check GPU Visibility
You can inspect the visible GPU devices inside a container:
docker run --rm \
--gpus all \
nvidia/cuda:12.6.3-base-ubuntu22.04 \
bash -c 'nvidia-smi -L'
The command lists the GPU devices available to the container.
Understand CUDA Compatibility
A CUDA application requires a compatible combination of:
NVIDIA driver.
CUDA runtime.
CUDA libraries.
GPU architecture.
Application framework.
A container image may contain a CUDA runtime that is newer than the version supported by the host driver.
This can cause errors when the application starts.
Always check the CUDA compatibility requirements for the selected image and NVIDIA driver.
9. Build a CUDA-Enabled Docker Application
Running nvidia-smi verifies GPU visibility, but it does not prove that your application can execute CUDA operations.
Let's create a small CUDA-enabled Python application.
The example will use PyTorch to perform a matrix multiplication on the GPU.
Create the Project
Create a directory:
mkdir gpu-docker-demo
cd gpu-docker-demo
Create a file named app.py:
import torch
import time
print("PyTorch version:", torch.__version__)
if not torch.cuda.is_available():
raise RuntimeError("CUDA GPU is not available")
device = torch.device("cuda")
print("GPU:", torch.cuda.get_device_name(0))
size = 4096
a = torch.rand(size, size, device=device)
b = torch.rand(size, size, device=device)
torch.cuda.synchronize()
start = time.perf_counter()
result = torch.matmul(a, b)
torch.cuda.synchronize()
end = time.perf_counter()
print("Matrix multiplication completed")
print("Result shape:", result.shape)
print("Execution time:", end - start, "seconds")
print("GPU memory allocated:",
torch.cuda.memory_allocated() / 1024**2,
"MB")
Understand the Python Code
The application first imports PyTorch and checks CUDA availability.
if not torch.cuda.is_available():
raise RuntimeError("CUDA GPU is not available")
This prevents the application from continuing when CUDA cannot be initialized.
The following statement selects the GPU:
device = torch.device("cuda")
The two matrices are created directly on GPU memory:
a = torch.rand(size, size, device=device)
b = torch.rand(size, size, device=device)
The matrix multiplication runs through PyTorch's CUDA-enabled execution path.
The torch.cuda.synchronize calls are important because GPU operations are generally asynchronous. Without synchronization, the measured time may include only the time required to submit the operation rather than the time required to complete it.
The example is a basic functional test, not a standardized GPU performance benchmark.
10. Create a CUDA Dockerfile
Create a file named Dockerfile.
Use the following configuration:
FROM pytorch/pytorch:2.6.0-cuda12.6-cudnn9-runtime
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]
This image provides a PyTorch environment with CUDA runtime libraries.
The application file is copied into the container.
The CMD instruction runs the Python application when the container starts.
For production, select and validate a currently supported PyTorch image that matches your NVIDIA driver and CUDA requirements. The version above is a reproducible example, not a recommendation to use an old image indefinitely.
Build the Image
Run:
docker build -t gpu-docker-demo .
Docker downloads the base image if it is not available locally and creates the application image.
Run the Container With GPU Access
Execute:
docker run --rm \
--gpus all \
gpu-docker-demo
Expected output will contain information similar to:
PyTorch version: 2.6.0
GPU: NVIDIA GeForce RTX
Matrix multiplication completed
Result shape: torch.Size([4096, 4096])
Execution time: ...
GPU memory allocated: ...
The actual execution time depends on GPU architecture, available memory, driver version, and system configuration.
This example verifies that PyTorch can allocate GPU memory and execute a CUDA operation inside Docker.
11. Use GPU Containers With Docker Compose
Real applications usually contain more than one service.
For example, an AI application may have:
Docker Compose can manage these services together.
Create a compose.yaml file:
services:
inference:
build:
context: .
container_name: gpu-inference
gpus: all
environment:
NVIDIA_VISIBLE_DEVICES: all
restart: unless-stopped
The important configuration is:
gpus: all
It requests GPU access for the inference container.
The NVIDIA_VISIBLE_DEVICES environment variable can also be used by compatible NVIDIA container workloads to control visible GPU devices.
Start the service:
docker compose up --build
View the logs:
docker compose logs -f inference
Stop the application:
docker compose down
This approach is useful for developers who want to run GPU-enabled application services alongside other development dependencies.
For production systems, define appropriate resource limits, service health checks, restart policies, logging, and secret management.
12. Monitor GPU Usage While Containers Are Running
Once the GPU container is running, developers should monitor GPU utilization and memory usage.
Open another PowerShell or WSL terminal.
Run:
nvidia-smi
The command displays:
GPU utilization.
Memory utilization.
Running GPU processes.
Temperature.
Power usage.
Driver information.
For continuous monitoring, use:
nvidia-smi -l 1
This refreshes the output every second.
You can also monitor GPU processes using:
nvidia-smi pmon -c 1
This provides process-level monitoring information where supported.
Monitor From Inside the Container
Run:
docker exec -it gpu-inference nvidia-smi
This allows developers to inspect GPU information from the running container.
The command works when the container includes the NVIDIA management utility and has GPU access configured.
Understand Important GPU Metrics
Metric | Meaning |
|---|
GPU Utilization | Percentage of time the GPU is actively processing |
Memory Used | GPU memory allocated to applications |
Temperature | Current GPU temperature |
Power Usage | Current GPU power consumption |
GPU Processes | Processes using the GPU |
Compute Mode | GPU compute access configuration |
High GPU utilization does not always mean an application is performing efficiently.
For example, an inference application may use substantial GPU memory but have low utilization because it is waiting for input data or processing requests sequentially.
Measure application throughput and latency alongside GPU metrics.
13. Run a GPU-Accelerated AI Model
After validating basic CUDA execution, the next step is running an actual AI model.
For example, developers can use Docker Model Runner to run supported language models with GPU acceleration.
Docker documents a GPU-enabled vLLM workflow.
Install the Docker Model Runner with the CUDA backend:
docker model install-runner \
--backend vllm \
--gpu cuda
Check the runner status:
docker model status
Run a supported model:
docker model run ai/smollm2-vllm hi
This example uses Docker Model Runner and vLLM to run a language model with GPU acceleration.
The actual GPU requirements depend on the model size, precision, inference engine, and available GPU memory.
A smaller model may run on a consumer GPU, while a larger model may require multiple GPUs or a remote inference service.
Understand the AI Inference Workflow
User Prompt
|
v
AI Application
|
v
Docker Container
|
v
vLLM Engine
|
v
CUDA Runtime
|
v
NVIDIA GPU
|
v
Generated Response
The AI application sends the prompt to the inference engine.
The inference engine uses CUDA-enabled operations to execute model computations on the GPU.
This makes Docker GPU support useful for local AI development, model evaluation, experimentation, and prototyping.
14. Troubleshoot Common GPU Container Problems
GPU configuration involves several layers. A problem in any one of them can prevent containers from accessing the GPU.
Error: No CUDA-Capable Device Is Detected
Possible causes include:
NVIDIA driver is outdated.
WSL 2 is not updated.
Docker Desktop is not using the WSL 2 backend.
The container was started without GPU access.
The selected image does not support the installed GPU.
Start by checking the GPU on Windows:
nvidia-smi
Then check inside WSL:
nvidia-smi
Finally, test inside Docker:
docker run --rm \
--gpus all \
nvidia/cuda:12.6.3-base-ubuntu22.04 \
nvidia-smi
This sequence identifies which layer is failing.
Error: Docker Does Not Recognize the --gpus Option
Check Docker Engine:
docker version
Check Docker information:
docker info
Confirm that Docker Desktop is using Linux containers and the WSL 2 backend.
Also update Docker Desktop if the installed version is outdated.
Error: CUDA Driver Version Is Insufficient
This usually indicates a compatibility problem between the host NVIDIA driver and the CUDA runtime expected by the container.
Check the Windows driver:
nvidia-smi
Review the CUDA compatibility requirements for the selected container image.
Update the NVIDIA driver if necessary.
Do not assume that installing a newer CUDA Toolkit inside the container will fix an incompatible host driver.
Error: GPU Works in WSL but Not in Docker
If nvidia-smi works inside Ubuntu but fails inside a container, focus on Docker Desktop configuration.
Verify:
Docker Desktop is running.
The WSL 2 backend is enabled.
Docker is running Linux containers.
The container is started with --gpus.
The selected image contains compatible CUDA components.
Restart Docker Desktop after updating WSL or NVIDIA drivers if required.
Error: Container Runs but Uses the CPU
Some frameworks automatically fall back to CPU execution.
For PyTorch, check:
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
If CUDA is unavailable, the application may be using a CPU-only framework image.
Use a CUDA-enabled framework build and verify that the GPU is accessible before running the application.
Error: GPU Memory Is Exhausted
A container can access the GPU but still fail when it tries to allocate more memory than is available.
Possible solutions include:
Reduce model batch size.
Reduce input resolution.
Use a smaller model.
Apply supported quantization.
Reduce concurrent requests.
Close other GPU applications.
Monitor memory usage with:
nvidia-smi
15. Docker GPU Support: WSL 2 vs. Other Backends
Docker Desktop for Windows provides multiple virtualization backends, but GPU passthrough support differs.
Feature | WSL 2 | Hyper-V | Docker VMM |
|---|
Linux containers | Supported | Supported | Supported |
NVIDIA GPU passthrough using --gpus | Supported | Not supported | Not supported |
WSL integration | Full integration | Not available | Docker CLI only |
GPU-PV | Supported | Not supported through this workflow | Not supported |
Main use | Linux development and GPU workloads | Virtualized container workloads | Container-focused virtualization |
For NVIDIA GPU containers on Windows, WSL 2 is the appropriate Docker Desktop backend.
This distinction is particularly important for developers evaluating Docker VMM after using it for file I/O performance improvements. Docker VMM and WSL 2 do not provide identical GPU capabilities.
If your development environment depends on NVIDIA CUDA containers, verify the GPU requirements before switching virtualization backends.
16. Best Practices for Production-Ready GPU Containers
Use Compatible Base Images
Select a CUDA-enabled base image that matches the NVIDIA driver and application framework requirements.
Prefer maintained, versioned images rather than relying on an unpinned latest tag.
Keep the Windows Driver Updated
The host NVIDIA driver is responsible for GPU support inside WSL 2.
Keep it updated using the appropriate NVIDIA driver release.
Avoid Installing Conflicting Drivers
Do not install a generic Linux NVIDIA kernel driver inside WSL when using the standard WSL GPU integration.
Follow NVIDIA's WSL-specific guidance.
Use Native Linux Container Images
Use Linux images that support the target GPU architecture and CUDA version.
Do not confuse Windows containers with Linux containers. The workflow described in this article uses Linux containers.
Monitor GPU Utilization
Track GPU memory, utilization, temperature, and application-level performance.
A working GPU container does not guarantee efficient GPU utilization.
Secure the Container Environment
Avoid running containers with unnecessary privileges.
Use appropriate volume permissions, secrets, network restrictions, and image scanning.
Validate on Target Hardware
A container that works on one NVIDIA GPU may behave differently on another GPU because of architecture, memory capacity, and CUDA compatibility.
Test the application on the hardware that will run it.
Use Production GPU Infrastructure for Heavy Workloads
Docker Desktop is useful for development and local testing.
For large-scale production AI workloads, consider dedicated GPU infrastructure such as Amazon EC2 accelerated instances or other supported GPU platforms.
Conclusion
Docker Desktop with WSL 2 makes it possible to run NVIDIA GPU-accelerated Linux containers on Windows without maintaining a separate Linux machine.
The key is understanding how Windows NVIDIA drivers, WSL 2 GPU Paravirtualization, Docker Desktop, and CUDA-enabled container images work together.
In this tutorial, we configured WSL 2, enabled Docker's WSL backend, verified GPU access, ran an NVIDIA CUDA container, built a PyTorch application, and explored GPU monitoring and troubleshooting.
The most important configuration requirement is to use Docker Desktop's WSL 2 backend for NVIDIA GPU passthrough through the --gpus option. Docker VMM and Hyper-V do not currently provide this same passthrough workflow.
Once the environment is configured correctly, developers can use Windows workstations for local AI experimentation, machine learning development, CUDA testing, image processing, and other GPU-accelerated container workloads.
Join the conversation! Your thoughts help the community grow.