引言

如果在 docker 使用 gpu 的时候,出现以下错误:

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

可以参考以下步骤安装 nvidia-container-toolkit 以支持 docker 使用显卡。

官网地址:

Installing the NVIDIA Container Toolkit — NVIDIA Container Toolkit 1.16.2 documentation

过程

Installing with Yum or Dnf

Configure the production repository:

1
2
curl -s -L <https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo> | \
sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo

Optionally, configure the repository to use experimental packages:

1
sudo yum-config-manager --enable nvidia-container-toolkit-experimental

Install the NVIDIA Container Toolkit packages:

1
2
3
4
5
6
# 更新仓库
sudo dnf clean all
sudo dnf makecache

# 安装 NVIDIA Container Toolkit
sudo dnf install -y nvidia-container-toolkit

Configure the container runtime by using the nvidia-ctk command:

1
sudo nvidia-ctk runtime configure --runtime=docker

Restart the Docker daemon:

1
sudo systemctl restart docker

结论

引用

  1. [docker: Error response from daemon: could not select device driver “” with capabilities: [[gpu]]. AFTER installing nvidia-docker2 - Stack Overflow](https://stackoverflow.com/questions/75118992/docker-error-response-from-daemon-could-not-select-device-driver-with-capab)