Docker-Ubuntu 安装 nvidia-docker

安装

设置Key

Setup the package repository and the GPG key

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/$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

Ubuntu LTS (18.04, 20.04, and 22.04) and Debian (Stretch, Buster) distributions

更新安装

sudo apt-get update
sudo apt-get install -y nvidia-docker2

测试

sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

打印显卡信息即为成功

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            On   | 00000000:00:1E.0 Off |                    0 |
| N/A   34C    P8     9W /  70W |      0MiB / 15109MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

后续设置

后续使用时可能会出现

Unknown runtime specified nvidia

需要修改Docker的daemon.json文件, 添加runtimes字段

{
    "registry-mirrors": ["加速仓库地址"],
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
         }	
    }
}

再重启Docker即可

sudo systemctl daemon-reload
sudo systemctl restart docker

参考链接🔗: 官方安装文档

posted @ 2022-07-30 22:06  漫漫长夜何时休  阅读(719)  评论(0编辑  收藏  举报