加nvidia-container-runtime的源
curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sudo apt-get install nvidia-container-runtime
停止docker
systemctl stop docker
把运行时添加到docker中:
dockerd --add-runtime=nvidia=/usr/bin/nvidia-container-runtime
创建容器时一定要指定gpus参数
docker run -it --gpus=all 镜像名 执行命令
进入容器后执行
nvidia-smi