# docker run --gpus

# 命令介绍

sudo docker run --gpus命令是指定当前docker容器所能使用的gpus,
当指定为all时,可以使用host上的所有gpu


sudo docker run --gpus all ...

# 常见问题

could not select device driver "" with capabilities: [[gpu]]

这是因为没有安装NVIDIA Container Toolkit所导致的,可以参考官方的指导安装nvidia-docker

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit

有时候,上面命令会报出如下错误,

Unable to locate package nvidia-container-toolkit" on Debian x86_64

这种情况是当前源列表中找不到nvidia-container-toolkit所导致。

官方文档给出的解决办法为:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
      && curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container.list | \
         sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
         sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

sudo apt-get update

sudo apt-get install -y nvidia-container-toolkit

sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
(adsbygoogle = window.adsbygoogle || []).push({});