Dima Lituiev
Dima Lituiev

Reputation: 13116

running nvidia-docker on Windows 10 + WSL2

I saw several Q&As on this topic and tried both approaches. Any advice on how to proceed with either route are appreciated:

Running nvidia-docker from within WSL2

I followed NVIDIA docs and this tutorial. Everything installs and docker command runs from within Ubuntu 20.04. However, sudo service docker start returns:
docker: unrecognized service

Update: this turns to be a known issue. I was able to install and run docker on Ubuntu following these instructions. However, next I am running into an issue like this

$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

Running NVIDIA docker from Windows:

Another school of thought suggest removing docker from WSL Ubuntu and running Windows docker instead. Then one can connect to it from WSL. Well, I am not able to run nvidia-docker from Windows at all:

$ 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]].

Additionally, after removing docker from ubuntu I can still run docker from Ubuntu20.04 or when I run wsl from Powershell:

$ 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.

I have definitely enabled WSL2-based engine and integration for Ubuntu 20.04 enabled in two different tabs in Docker settings.

System

Windows 10
WSL 2
Ubuntu 20.04 within WSL2
Windows Docker with WSL2-based engine and integration enabled

Any help how to diagnose it further is much appreciated

Upvotes: 21

Views: 42303

Answers (3)

SamStephens
SamStephens

Reputation: 5861

As of June 2022, with Windows 10, I didn't have to do anything to enable this. I have a pre-existing Ubuntu 20.04 install on WSL 2, and Docker running on Windows with WSL 2 integration enabled. I ran docker run -it --rm --gpus all ubuntu nvidia-smi and it showed my GPU.

Upvotes: 13

anoy
anoy

Reputation: 1

by https://docs.docker.com/docker-for-windows/wsl/

  • uncheck "Enable integration with my default WSL distro" and apply,

  • then uncheck "Use the WSL 2 based engine" and apply.

  • check all above and enable: "Enable integration with additional distros:" Ubuntu-20.04

  • open terminal:

    docker ps 
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
    

it works on my win10 docker 3.6...

Upvotes: -1

Khalil Meftah
Khalil Meftah

Reputation: 73

I think the best way to get nVidia GPU (CUDA) running on WSL2 is to follow the tutorial from nVidia documentation CUDA on WSL. There are three thing you need do them correctly and in order:

  1. First, check your windows if there is an updates, update if there is any. Then you need to subscribe in Microsoft Windows Insider Program, specifically subscribe in Dev Channel (Fast ring). Make sure that is set to Dev channel not Beta Channel nor Release Preview Channel. Here was the tricky part for me, after you select Dev channel check your windows version by running (winver) program (search for it in the search bar of windows) if it's below 20145 go re-check your windows for an update (you will see in the update discription version above 20145 is availble). You nedd to install it, here you need to be patient because it take while to download and install the update, it will ask you for windows restart. After the restart you're good to go (you will also notice some design diffrence between the two version of windows). Check again your windows version with (winver) to find it, it's indeed above 20145.
  2. Next, install the NVIDIA preview driver for WSL 2, it's pretty straight forward process.
  3. Finally, install WSL2 from tutorial, this is also pretty straight forward process. Personaly, i follewed this youtube tutorial from David Bombal channel.

After these three steps preformed correctly, you can follow along the nVidia tutorial from Setting up CUDA Toolkit. Here is another nVidia document stating the same issue you're facing in Chapter 8. They claim that 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.

For me, it was my Windows Insider Preview Builds version not properly set to version 20145 or higher.

Upvotes: 4

Related Questions