[Notes] Ubuntu安装nvidia-docker2

糊一笑 2019-11-25

ubuntu版本为16.04.1 LTS (Xenial Xerus)。

本系统已安装nvidia驱动,但是未安装docker。

参考官方文档进行安装:https://docs.docker.com/install/linux/docker-ce/ubuntu/

然后在参考nvidia-docker github页进行安装:https://github.com/NVIDIA/nvidia-docker

一体化安装脚本:

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install     apt-transport-https     ca-certificates     curl     gnupg-agent     software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "chekc the fingureprint!"
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu    $(lsb_release -cs)    stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
# install nvidia-docker2
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 | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

如果安装的docker版本比较新,那么nvidia-docke2可能就自带了,上面脚本的下半截可能就没啥用(从distribution开始)。

下面验证安装 成功,参考:https://github.com/NVIDIA/nvidia-docker

例如本机有两块显卡,运行下述验证:

docker run --gpus 2 nvidia/cuda:9.0-base nvidia-smi

相关推荐