在 Windows 10 + WSL2 上运行 nvidia-docker

Dim*_*iev 8 nvidia docker nvidia-docker wsl-2 ubuntu-20.04

我看到了几个关于这个主题的问答,并尝试了这两种方法。任何关于如何继续任何一条路线的建议表示赞赏:

从 WSL2 中运行 nvidia-docker

我关注了NVIDIA 文档本教程。一切都docker在 Ubuntu 20.04 中安装和运行。但是,sudo service docker start返回:
docker: unrecognized service

更新:这变成了一个已知问题。我能够按照这些说明在 Ubuntu 上安装和运行 docker 。但是,接下来我遇到了这样问题

$docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
Status: Downloaded newer image for nvcr.io/nvidia/k8s/cuda-sample:nbody
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: initialization error: nvml error: driver not loaded: unknown.
ERRO[0065] error waiting for container: context canceled
Run Code Online (Sandbox Code Playgroud)
  • WSL1这里有一个类似的问题,建议安装 WSL2。我在 WSL2 下遇到了同样的事情。

从 Windows 运行 NVIDIA docker:

另一种思想流派建议从 WSL Ubuntu 中删除 docker 并改为运行 Windows docker。然后可以从 WSL 连接到它。好吧,我根本无法nvidia-docker从 Windows运行:

$ docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
Unable to find image 'nvcr.io/nvidia/k8s/cuda-sample:nbody' locally
nbody: Pulling from nvidia/k8s/cuda-sample
...
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
Run Code Online (Sandbox Code Playgroud)
  • 对于如何解决它的技巧在这里,但它是所有关于码头工人在Linux中运行。哪个不起作用(见上文)。

此外,从 ubuntu 中删除 docker 后,我仍然可以从 Ubuntu20.04 或wsl从 Powershell运行时运行 docker :

$ which docker
/mnt/c/ProgramData/DockerDesktop/version-bin/docker
$ docker 
The command 'docker' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.
Run Code Online (Sandbox Code Playgroud)

我已经在 Docker 设置的两个不同选项卡中为 Ubuntu 20.04 启用了基于 WSL2 的引擎和集成。

系统

Windows 10
WSL 2
Ubuntu 20.04 within WSL2
Windows Docker with WSL2-based engine and integration enabled
Run Code Online (Sandbox Code Playgroud)

非常感谢如何进一步诊断它的任何帮助

Sam*_*ens 10

截至 2022 年 6 月,在 Windows 10 中,我无需执行任何操作即可启用此功能。我在 WSL 2 上安装了预先存在的 Ubuntu 20.04,并且在启用了 WSL 2 集成的 Windows 上运行 Docker。我跑了一下docker run -it --rm --gpus all ubuntu nvidia-smi,它显示了我的 GPU。


Kha*_*tah 4

我认为在 WSL2 上运行 nVidia GPU (CUDA) 的最佳方法是遵循WSL 上的 nVidia 文档 CUDA中的教程。您需要正确且按顺序执行三件事:

  1. 首先,检查您的Windows是否有更新,如果有则更新。那么你需要在Microsoft Windows Insider Program中订阅,具体是在 Dev Channel(快环)中订阅。确保将其设置为 Dev 通道,而不是 Beta 通道或 Release Preview 通道。这对我来说是棘手的部分,在您选择 Dev 频道后,通过运行 (winver) 程序(在 Windows 的搜索栏中搜索它)检查您的 Windows 版本,如果它低于 20145,请重新检查您的 Windows 是否有更新(您将请参阅更新说明,20145 以上版本可用)。您需要安装它,这里您需要耐心等待,因为下载和安装更新需要一段时间,它会要求您重新启动Windows。重新启动后,您就可以开始了(您还会注意到两个版本的 Windows 之间存在一些设计差异)。再次用(winver)检查一下你的windows版本,发现它确实在20145以上。
  2. 接下来,安装WSL 2 的 NVIDIA 预览驱动程序,这是一个非常简单的过程。
  3. 最后,从教程中安装 WSL2 ,这也是一个非常简单的过程。就我个人而言,我遵循了David Bombal频道的YouTube教程。

正确执行这三个步骤后,您可以按照设置 CUDA 工具包中的nVidia 教程进行操作。这是另一个nVidia 文档,说明了您在第 8 章中遇到的相同问题。他们声称This error usually indicates that the right Microsoft Windows Insider Preview Builds, WSL 2, NVIDIA drivers and NVIDIA Container Toolkit may not be installed correctly.

对我来说,这是我的 Windows Insider Preview Builds 版本未正确设置为版本 20145 或更高版本。