How to get Docker to recognize NVIDIA drivers? How to get Docker to recognize NVIDIA drivers? docker docker

How to get Docker to recognize NVIDIA drivers?


I got the same error. After trying number of solutions I found the below

docker run -ti --runtime=nvidia -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all <image_name>


In order for docker to use the host GPU drivers and GPUs, some steps are necessary.

  • Make sure an nvidia driver is installed on the host system
  • Follow the steps here to setup the nvidia container toolkit
  • Make sure cuda, cudnn is installed in the image
  • Run a container with the --gpus flag (as explained in the link above)

I guess you have done the first 3 points because nvidia-docker2 is working. So since you don't have a --gpus flag in your run command this could be the issue.

I usually run my containers with the following command

docker run --name <container_name> --gpus all -it <image_name>

-it is just that the container is interactive and starts a bash environment.


For me, I was running from a vanilla ubuntu base docker image, i.e.

FROM ubuntu

Changing to an Nvidia-provided Docker base image solved the issue for me:

FROM nvidia/cuda:11.2.1-runtime-ubuntu20.04