安装 nvidia-docker 之前要先安装好显卡驱动和docker,不需要安装CUDA
1、安装docker
先卸载旧版本dockersudo apt-get remove docker docker-engine docker.io containerd runc
再进行
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
# Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Use the following command to set up the repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装docker
sudo apt-get update
# 安装最新版docker
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 查看docker版本
docker --version
# 查看已有镜像
docker images # 出错,需要加sudo才行
为避免每次都需要加 sudo ,可进行下列操作
sudo groupadd docker
sudo usermod -aG docker $USER #最后是获取用户名
#重启docker服务
sudo service docker restart
newgrp - docker
再次查看镜像
docker images
2、安装nvidia-docker
设置distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
开始安装
sudo apt-get update
sudo apt-get install -y nvidia-docker2
# restart
sudo systemctl restart docker
# test , running a base CUDA container
sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
3、docker国内镜像加速
在进行docker pull时会很慢,需要配置国内加速器sudo vim /etc/docker/daemon.json
添加以下内容
{
"registry-mirrors": [
"https://ung2thfc.mirror.aliyuncs.com",
"https://registry.docker-cn.com","http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.baidubce.com"
],
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime", "runtimeArgs": []
}
}
}
保存退出,重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
验证是否成功
docker info
这样再pull时就快得飞起