Windows系统Docker是否支持GPU透传?容器内GPU调用问题求解
Absolutely, Docker on Windows 10 does support GPU pass-through—but the setup varies based on your Docker backend. The WSL 2 backend is the modern, user-friendly path (and what most people use these days), so we’ll focus on that first, with a note on the more complex Hyper-V alternative.
Prerequisites
Before you start, make sure you meet these requirements:
- Windows 10 Version: You need at least Windows 10 2004 (Build 19041) or later. Check this by pressing
Win + R, typingwinver, and verifying the version number. - Updated GPU Drivers:
- For NVIDIA: Install the latest NVIDIA Driver for WSL (not the standard desktop driver—look for this specific package on NVIDIA’s website).
- For AMD: Use the AMD Adrenalin software to update to a driver version that supports WSL GPU integration.
- For Intel: Install the latest Intel graphics driver with WSL support.
- Docker Desktop with WSL 2 Enabled: Ensure Docker Desktop is set to use the WSL 2 backend (this is the default for new installs, but worth confirming).
Step-by-Step Setup (WSL 2 Backend)
Enable WSL 2 (if not already done)
- Open PowerShell as Administrator (right-click Start → Windows PowerShell (Admin)).
- Run the command:
wsl --install - Restart your computer when prompted. This installs Ubuntu as the default WSL 2 distro, but you can use any distro you prefer.
Configure Docker Desktop for WSL 2
- Open Docker Desktop, click the gear icon (Settings) in the top-right corner.
- Go to General and check the box for Use the WSL 2 based engine.
- Navigate to Resources → WSL Integration and toggle on the WSL 2 distro you want to use (e.g., Ubuntu).
- Click Apply & Restart to save changes.
Run a GPU-Aware Container
- Open a command prompt or PowerShell window.
- For NVIDIA GPUs, run this test command to verify GPU access:
docker run --rm --gpus all nvidia/cuda:11.8.0-base-ubuntu22.04 nvidia-smi - For AMD GPUs, use this command instead:
docker run --rm --gpus all rocm/pytorch:latest rocm-smi - For Intel GPUs, test with:
docker run --rm --gpus all intel/oneapi-basekit:latest sycl-ls
If everything works, you’ll see output showing your GPU model, driver version, and other details.
Troubleshooting Common Issues
- "GPU not found" errors in Docker:
- First, check if WSL 2 can access the GPU directly. Open your WSL 2 distro terminal and run
nvidia-smi(NVIDIA) orrocm-smi(AMD). If this fails, your GPU driver isn’t properly set up for WSL 2—reinstall the WSL-specific driver. - Ensure Docker Desktop’s WSL Integration is enabled for your distro. Double-check the Settings menu.
- First, check if WSL 2 can access the GPU directly. Open your WSL 2 distro terminal and run
- No WSL Integration option in Docker Desktop:
- This means WSL 2 isn’t installed or configured correctly. Re-run
wsl --installand make sure your Windows version meets the minimum requirement.
- This means WSL 2 isn’t installed or configured correctly. Re-run
- Hyper-V conflicts: If you had Hyper-V enabled before switching to WSL 2, ensure Docker is set to use WSL 2 (not Hyper-V) in the General settings.
Hyper-V Mode Alternative (Advanced)
If you must use the Hyper-V backend (not recommended for most users), you can enable GPU pass-through via Discrete Device Assignment (DDA). This requires:
- Disabling Secure Boot in your BIOS/UEFI.
- Uninstalling the GPU driver from Windows (so it can be assigned to the Hyper-V VM).
- Using PowerShell commands to attach the GPU to the Docker VM.
This process is far more complex and can cause stability issues, so stick with WSL 2 unless you have a specific reason to use Hyper-V.
内容的提问来源于stack exchange,提问作者Srihari Humbarwadi




