Ubuntu 22.04 LTS 安装nvidia-docker NVIDIA Container Toolkit

安装docker

sudo apt install docker.io

docker info

yeqiang@yeqiang-MS-7B23:~$ sudo docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 12
  Running: 0
  Paused: 0
  Stopped: 12
 Images: 67
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.19.0-50-generic
 Operating System: Ubuntu 22.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 31.28GiB
 Name: yeqiang-MS-7B23
 ID: WBWU:NTCF:2B5D:VXMX:DYYI:PUYQ:WL2A:7SAJ:5ZS2:LYIZ:VM7A:DIHQ
 Docker Root Dir: /home/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live 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:/# 

你可能感兴趣的:(ai,nvidia,docker,ubuntu,docker,nvidia)