docker gpu报错Error response from daemon: could not select device driver ““ with capabilities: [[gpu]]

Docker container using Nvidia GPU error docker: Error response from daemon: could not select device driver “” with capabilities: [[gpu]]

There was a problem

We know that if you want to use nvidia gpu in docker19 and later versions, you don't need to install nvidia-docker separately, which has been integrated into docker.

As everyone knows, to use the GPU of the host machine, you need to add the --gpus [xxx] parameter when docker run. However, after we have just installed docker and built the image, it is problematic to run it directly like this, namely:

docker run -it --gpus all image_name:tag_name

There will be an error report like this:

docker: Error response from daemon: could not select device driver “” with capabilities: [[gpu]].

solution

In fact, when we use the host's GPU through the --gpus parameter, we need to install an NVIDIA container runtime first .

Another thing to note is that this thing cannot be apt installed directly, and it will report that the software cannot be found. You need to add NVIDIA's apt software source first. The specific operation steps are as follows:

1 Add source

Put the following script anywhere,

# nvidia-container-runtime-script.sh

sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update

and execute:

sudo sh nvidia-container-runtime-script.sh

You will get output similar to the following:

OK
deb https://nvidia.github.io/libnvidia-container/ubuntu18.04/$(ARCH) /
deb https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/$(ARCH) /
Hit:1 http://archive.canonical.com/ubuntu bionic InRelease
Get:2 https://nvidia.github.io/libnvidia-container/ubuntu18.04/amd64  InRelease [1139 B]                
Get:3 https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/amd64  InRelease [1136 B]           
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease                                       
Get:5 https://nvidia.github.io/libnvidia-container/ubuntu18.04/amd64  Packages [4076 B]                 
Get:6 https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/amd64  Packages [3084 B]            
Hit:7 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic InRelease
Hit:8 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:9 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 9435 B in 1s (17.8 kB/s)                   
Reading package lists... Done

2 installation

After the first step, Nvidia's software source has been added, and then you can install it directly with apt:

sudo apt-get install nvidia-container-runtime

After the installation is complete, verify it by typing:

which nvidia-container-runtime

should get the output:

/usr/bin/nvidia-container-runtime

This indicates that the software has been installed normally.

3 Run the container

Once installed, we can run our container with GPU:

docker run -it --gpus all image_name:tag_name

At this time, no error will be reported, and the container will be entered normally.

4 Select GPU number

If you need to specify a certain GPU number, the specification is still very strict. The author personally tested that the following format is acceptable:

docker run -it --gpus '"device=0,2"' --shm-size 32g image_name:tag_name        


Original link: https://blog.csdn.net/weixin_44966641/article/details/123760614

Guess you like

Origin blog.csdn.net/dou3516/article/details/131970430