$ docker run --rm --gpus all nvidia/cuda:11.7.1-base-ubuntu22.04 nvidia-smi
Wed Aug 16 03:04:19 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.199.02 Driver Version: 470.199.02 CUDA Version: 11.7 | |-------------------------------+----------------------+----------------------+ | 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 Quadro M6000 Off | 00000000:03:00.0 Off | Off | | 28% 38C P8 13W / 250W | 15MiB / 12210MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+
可以看到,我们在 Docker 容器中可以正常使用 NVIDIA 显卡了。
下载 Docker 镜像
要运行 AI 环境,一般需要安装 CUDA 和 PyTorch,之前我们是在主机上安装这 2 个程序,但使用 Docker 的方式,我们可以直接下载已经安装好 CUDA 和 PyTorch 的镜像,这里推荐使用这个镜像:anibali/pytorch,这个镜像中包含了 CUDA 和 PyTorch,我们可以通过以下命令来运行镜像:
$ docker run --rm --gpus all anibali/pytorch:1.13.0-cuda11.8-ubuntu22.04 nvidia-smi
Wed Aug 16 03:09:33 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.199.02 Driver Version: 470.199.02 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 Quadro M6000 Off | 00000000:03:00.0 Off | Off | | 28% 38C P8 13W / 250W | 15MiB / 12210MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+