Guide to run CUDA + WSL + Docker with latest versions (21382 Windows build + 470.14 Nvidia)

Hi - this is for anyone else running into issues. It took me a long time - and lots of google searching - but I’ve got everything working finally.

  1. I assume you have WSL 2 working already. You don’t need to install a WSL distribution yet - we’ll come to that.

  2. ONLY follow the steps upto Installing Nvidia drivers at this stage. Don’t go any further!

  3. Now - to get Docker working - it’s actually very easy! The latest versions of Docker Desktop have their own WSL2 container support - with GPU support! There is a catch though. Use v 3.3.0 for Docker Destop (don’t go any higher!!!). 3.3.3 definitely crashes it. Also - 3.3.0 gives you the option to ignore future updates…

  1. At this stage - you should already have Docker working correctly - even in Windows!! There is another catch - we need to set a flag --env NVIDIA_DISABLE_REQUIRE=1 to get GPU support.

Here is my output (from WINDOWS!!)

(base) PS C:\Users\gyaan> docker run --env NVIDIA_DISABLE_REQUIRE=1 --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark

Compute 6.1 CUDA device: [NVIDIA GeForce GTX 1080 Ti]
28672 bodies, total time for 10 iterations: 21.033 ms
= 390.855 billion interactions per second
= 7817.098 single-precision GFLOP/s at 20 flops per interaction

  1. At this stage, if you haven’t installed a WSL distribution yet, you should see the following 2 WSL distributions pop up - as Docker installed them for you. Leave them alone!

(base) PS C:\Users\gyaan> wsl -l -v
NAME STATE VERSION
docker-desktop Running 2
docker-desktop-data Running 2

  1. Now you may install any WSL distribution of your liking. Before going any further - make sure you click this - to enable docker support within WSL directly. Docker may restart when you do so.

This will allow you to now run docker from within WSL - but using the same docker containers that you used in Windows!!

Let’s now try from WSL (Ubuntu):

gyaan@ubuntu ~> docker run --env NVIDIA_DISABLE_REQUIRE=1 --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark

Compute 6.1 CUDA device: [NVIDIA GeForce GTX 1080 Ti]
28672 bodies, total time for 10 iterations: 23.429 ms
= 350.881 billion interactions per second
= 7017.623 single-precision GFLOP/s at 20 flops per interaction

  1. Finally - if you want - you can install CUDA natively in that WSL distribution by following the rest of the steps upto the point “Docker installation” on the NVIDIA page. Don’t go any further. You already have Docker working in WSL!!

Good luck!

8 Likes

Hello, gurveshsanghera,

following your instructions I get the following error message:

PS C:\Users\max_m> docker run --env NVIDIA_DISABLE_REQUIRE=1 --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: initialization error: driver error: failed to process request: unknown.

1 Like

Hi Max

Looks like you used a version higher than 3.3.0 for Docker (or accidentally updated once it installed). See this thread:

https://github.com/NVIDIA/nvidia-docker/issues/1492

I had this issue in version 3.3.3 of Docker, but once I uninstalled, rebooted - then re-installed 3.3.0, it worked after that. Someone else also confirmed that this works (see bottom of the github page).

Make sure that after installing 3.3.0 of Docker Desktop from this page, you do not upgrade any further.

Hope that helps

All the best!

1 Like

Wow, indeed it works with Docker 3.3.0!
Many, many thanks gurveshsanghera!!!
:-) :-) :-)

You are the best! It works!!!
I actually don’t seem to need the: --env NVIDIA_DISABLE_REQUIRE=1

Thanks a lot. It works.
I do need the: --env NVIDIA_DISABLE_REQUIRE=1

Thanks for the guide! The benchmark is up and working for me when I run from windows, however when I try to run the third example (CUDA on WSL :: CUDA Toolkit Documentation) I get:

WARNING: The NVIDIA Driver was not detected.  GPU functionality will not be available.
   Use 'nvidia-docker run' to start this container

Where you able to run that example correctly and get the NVIDIA drivers detected?

Thanks a lot for this guide !!! It really helps!

Hi - I was able to get the tensorflow docker image running - if that’s your question. I checked the GPU was exposed in it, and was able to run some test cases. I was also able to install CUDA natively on the WSL (and also on Windows) and run the BlackScholes example (on both).

I can get the dockers running, but when I use this command:

docker run --gpus all -it --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 nvcr.io/nvidia/tensorflow:20.03-tf2-py3

there is the warning when the container starts and from there I haven’t been able to run the resnet examples that nvidia gave in their tutorial

I think you are missing the --env NVIDIA_DISABLE_REQUIRE=1 flag. You need it for all the docker containers now where you want to use the GPU.

This is the command I ran fyi:

docker run -it --env NVIDIA_DISABLE_REQUIRE=1 --gpus all --name tf1 -p 8888:8888 tensorflow/tensorflow:latest-gpu-py3-jupyter

Sorry I forgot to include that in the post but when I start my docker I use that, Tensorflow can find the GPU so I guess it can work I just don’t know if ill be able to use tensorrt in the container since it says it can’t find drivers

So - I’ve been thinking - why do we need to run containers at all now? I am also able to get tensorflow running natively on Windows (actually that’s what I have been doing last few days) - since they (and also Pytorch) are natively supporting Windows. And everything seems to work just fine.

Maybe using via the WSL Docker just adds too much complexity…

Anyway… all the best!

1 Like

I’m actually going to be running container in the cloud, so having same environment local is a huge win for me. I did go through the steps in original post and everything worked from GPU perspective! However I had to roll back because the latest windows build caused my system to hang and crash every 5 minutes or so. :( so i’m back to square one.

Thanks you very much!

Thanks, installing 3.0.0 did the trick.

For anyone who, after running the above docker run command in WSL2 got this error (like I did):

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied

The reason is that the user running the command is not a member of the docker group. To add yourself to the docker group, run:

sudo usermod -a -G docker $USER

Then logout and log back in.

After logging back in, confirm you are a member of the docker group by typing:

$ groups

You should see “docker” in the list displayed.

Otherwise, worked great! Just remember, if you copy & paste docker CUDA sample command lines from the NVIDIA pages, remember to add --env NVIDIA_DISABLE_REQUIRE=1 to the line you copied.

2021-06-27 the latest version Docker Desktop v3.5.1 (66090) works!

1 Like

Docker Desktop 3.5.1 66090 worked. Thanks!

Hi - to anyone reading this now - install Docker Desktop 3.5.1.66090 or higher directly. I have verified with both 3.6 and 4.0 - which both seem to work fine, and also no longer require the flag --env NVIDIA_DISABLE_REQUIRE=1.