安装好Nvidia驱动的Ubuntu服务器或者WSL2(后者一般自带显卡驱动)
通过nvidia-smi
验证是否安装好驱动,以及所安装的驱动和cuda的版本
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pQaywjO4-1660648016311)(image_1.daccfac4.png)]
如果没有安装好驱动可以尝试以下命令或自行百度安装
sudo apt update
sudo ubuntu-drivers devices # 查看显卡型号和推荐的驱动 sudo ubuntu-drivers autoinstall # 自动安装推荐的版本驱动
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L [https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list](https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list) | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo nano /etc/docker/daemon.json
在文件后面添加如下内容
{
"registry-mirrors": [
"[https://registry.docker-cn.com](https://registry.docker-cn.com)",
"[https://docker.mirrors.ustc.edu.cn](https://docker.mirrors.ustc.edu.cn)",
"[https://hub-mirror.c.163.com](https://hub-mirror.c.163.com)"
]
}
重启一下doker
sudo service docker stop
sudo service docker start # 重启一下docker
sudo gpasswd -a $USER docker
newgrp docker
docker pull pytorch/pytorch:latest
--gpus all
是调用显卡的命令)docker run --rm --gpus all pytorch/pytorch nvidia-smi