2024-09-09
docker
00
请注意,本文编写于 72 天前,最后修改于 71 天前,其中某些信息可能已经过时。

目录

结论
1. nvidia docker
2. nvidia docker2
3. nvidia-container-toolkits

结论

凡是使用了命令nvidia docker或者在docker中引入了--runtime=nvidia参数的都是过时教程,最新方法只需要下载nvidia-container-toolkits,在docker中引入--gpus参数即可

1. nvidia docker

nvidia docker是NVIDIA第一代支持docker容器内使用GPU资源的项目。运行时用nvidia-docker命令。

根据nvidia docker在github上的描述,已经不再使用了。

The nvidia-docker wrapper script that was included in this repository is no longer included in the package and a configuration specific to the target container engine (e.g. Docker, Containerd, Cri-o, or Podman) is suggested instead.

2. nvidia docker2

nvidia docker2是NVIDIA第二代支持docker容器内使用GPU资源的项目。运行时用nvidia-docker命令,且需要指定参数--runtime=nvidia.

根据github wiki的描述,一代和二代之间有如下兼容性。

Backward compatibility To help transitioning code from 1.0 to 2.0, a bash script is provided in /usr/bin/nvidia-docker for backward compatibility. It will automatically inject the --runtime=nvidia argument and convert NV_GPU to NVIDIA_VISIBLE_DEVICES.

也就是说,在二代中,既可以使用nvidia docker命令,这会自动引入参数--runtime=nvidia也可以使用docker命令,手动指定参数--runtime=nvidia 如帖子总结:

docker run --runtime=nvidia is only available since nvidia-docker v2. Both commands are equivalent with nvidia-docker v2, the former is a script provided for backward compatibility with nvidia-docker v1.

ps: 笔者上一次使用docker gpu 还停留在 nvidia docker2 的阶段. 技术果然在飞速进步啊.

3. nvidia-container-toolkits

根据github这是最新的支持方案,如帖子描述,nvidia docker2 被Nvidia container toolkits取代,无需指定--runtime参数,只需要传递--gpus参数

root@docker2-1:/# docker run --rm --gpus all ubuntu nvidia-smi Tue Sep 10 08:31:49 2024 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 550.107.02 Driver Version: 550.107.02 CUDA Version: 12.4 | |-----------------------------------------+------------------------+----------------------+ | 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 RTX 2080 Ti Off | 00000000:03:00.0 Off | N/A | | 0% 41C P0 57W / 300W | 1MiB / 11264MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ | 1 NVIDIA GeForce RTX 3060 Ti Off | 00000000:04:00.0 Off | N/A | | 0% 49C P0 46W / 220W | 1MiB / 8192MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+

原文链接:https://blog.csdn.net/yjy420/article/details/132305356

如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:王海生

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!