1.第一步首先做一些检查
nvcc --version查看,CUDA版本
查询不到 使用apt install nvidia-cuda-toolkit安装
首先用下面的命令更新apt 包的索引:
$ sudo apt-get update
把Docker仓库加进到apt里,反斜杠\代表一行,只是换行写更清晰:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加Docker的官方GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
验证当前你所拥有的key的指纹是9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88,方法是搜索指纹中的后八个字符。
$ sudo apt-key fingerprint 0EBFCD88
然后用下面的语句来建立稳定的仓库:
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
接下来正式安装docker:
$ sudo apt-get update
$ sudo apt-get install docker-ce
最后一个命令是验证docker是否安装成功,它会下载并执行hello-world镜像。如果安装正确,执行后的结果应该类似下面这样:
二、安装NVIDIA-Docker
安装完成Docker并检查安装正确(能跑出来hello-world)后,如果需要Docker容器中有GPU支持,需要再安装NVIDIA-Docker,同样参考该项目的主页(链接)。
可以看到在Quick start小节,选择我们Ubuntu的发行版,依次执行命令:
# Add the package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
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
正式安装NVIDIA-Docker:
# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
用最新的CUDA镜像来测试一下nvidia-smi(检查是否安装成功,安装成功,则会显示关于GPU的信息)。
# Test nvidia-smi with the latest official CUDA image
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi