安装docker
sudo apt install docker.io
docker info
yeqiang@yeqiang-MS-7B23:~$ sudo docker info
Client:Context: defaultDebug Mode: falseServer:Containers: 12Running: 0Paused: 0Stopped: 12Images: 67Server Version: 20.10.21Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: systemdCgroup Version: 2Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linuxDefault Runtime: runcInit Binary: docker-initcontainerd version: runc version: init version: Security Options:apparmorseccompProfile: defaultcgroupnsKernel Version: 5.19.0-50-genericOperating System: Ubuntu 22.04.2 LTSOSType: linuxArchitecture: x86_64CPUs: 6Total Memory: 31.28GiBName: yeqiang-MS-7B23ID: WBWU:NTCF:2B5D:VXMX:DYYI:PUYQ:WL2A:7SAJ:5ZS2:LYIZ:VM7A:DIHQDocker Root Dir: /home/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false
安装NVIDIA Container Toolkit
配置apt源
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
安装nvidia-container-toolkit
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
安装日志
命中:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
命中:2 http://packages.microsoft.com/repos/code stable InRelease
命中:3 https://dl.google.com/linux/chrome/deb stable InRelease
命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
获取:5 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 InRelease [1,484 B]
命中:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
命中:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
命中:8 http://security.ubuntu.com/ubuntu jammy-security InRelease
命中:9 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-proposed InRelease
获取:10 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 Packages [29.2 kB]
已下载 30.7 kB,耗时 1秒 (28.0 kB/s)
正在读取软件包列表... 完成
W: https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64/InRelease: 密钥存储在过时的 trusted.gpg 密钥环中(/etc/apt/trusted.gpg),请参见 apt-key(8) 的 DEPRECATION 一节以了解详情。
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
将会同时安装下列软件:libnvidia-container-tools libnvidia-container1 nvidia-container-toolkit-base
下列【新】软件包将被安装:libnvidia-container-tools libnvidia-container1 nvidia-container-toolkit nvidia-container-toolkit-base
升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 71 个软件包未被升级。
需要下载 4,050 kB 的归档。
解压缩后会消耗 15.7 MB 的额外空间。
获取:1 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 libnvidia-container1 1.13.5-1 [928 kB]
获取:2 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 libnvidia-container-tools 1.13.5-1 [24.9 kB]
获取:3 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 nvidia-container-toolkit-base 1.13.5-1 [2,244 kB]
获取:4 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 nvidia-container-toolkit 1.13.5-1 [853 kB]
已下载 4,050 kB,耗时 12秒 (337 kB/s)
正在选中未选择的软件包 libnvidia-container1:amd64。
(正在读取数据库 ... 系统当前共安装有 263151 个文件和目录。)
准备解压 .../libnvidia-container1_1.13.5-1_amd64.deb ...
正在解压 libnvidia-container1:amd64 (1.13.5-1) ...
正在选中未选择的软件包 libnvidia-container-tools。
准备解压 .../libnvidia-container-tools_1.13.5-1_amd64.deb ...
正在解压 libnvidia-container-tools (1.13.5-1) ...
正在选中未选择的软件包 nvidia-container-toolkit-base。
准备解压 .../nvidia-container-toolkit-base_1.13.5-1_amd64.deb ...
正在解压 nvidia-container-toolkit-base (1.13.5-1) ...
正在选中未选择的软件包 nvidia-container-toolkit。
准备解压 .../nvidia-container-toolkit_1.13.5-1_amd64.deb ...
正在解压 nvidia-container-toolkit (1.13.5-1) ...
正在设置 nvidia-container-toolkit-base (1.13.5-1) ...
正在设置 libnvidia-container1:amd64 (1.13.5-1) ...
正在设置 libnvidia-container-tools (1.13.5-1) ...
正在设置 nvidia-container-toolkit (1.13.5-1) ...
正在处理用于 libc-bin (2.35-0ubuntu3.2) 的触发器 ...
验证安装
root@yeqiang-MS-7B23:~# systemctl restart docker
root@yeqiang-MS-7B23:~# docker run --rm -it --gpus all ubuntu:22.04 /bin/bash
root@cad0abb4936b:/# nvidia-smi
Tue Aug 1 00:57:29 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 520.61.05 Driver Version: 520.61.05 CUDA Version: 11.8 |
|-------------------------------+----------------------+----------------------+
| 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 NVIDIA GeForce ... Off | 00000000:01:00.0 On | N/A |
| 0% 51C P8 21W / 160W | 528MiB / 6144MiB | 29% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
root@cad0abb4936b:/#