Nvidia-docker 2.0 的优于1.0的地方在于对K8S的支持。凭借 兼容 Kubernetes 的 device plugin 机制,极大的提高了其使用性能,本文将手把手教你安装运行。

安装显卡驱动以及CUDA

1. 通过“lspci” 功能来验证显卡,目前只能支持CUDA兼容的NVIDIA显卡

lspci | grep VGA

00:02.0 VGA compatible controller: Intel Corporation [...] (rev 09)
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2)

2. 安装CUDA,因为CUDA以及包括了一个显卡驱动,所以不需要安装而外的驱动。

2.1 加载CUDA仓库

# Install NVIDIA repo metadata
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo dpkg --install cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

# Install CUDA GPG key
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub

2.2 安装CUDA

sudo apt-get update
sudo apt install cuda

安装Nidia-docker

1. 如果已经预先安装的docker,首先需要卸载

sudo apt-get purge docker-ce

2. 安装 docker.io

sudo apt-get update
sudo apt-get install -y docker.io

3. 测试

sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
...

4. 开始安装 Nvidia Docker 2.0

4.1 预先加载Nvidia提供的库

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

4.2 安装所需的软件包

sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

5. 测试

sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.93       Driver Version: 410.93       CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro K620         Off  | 00000000:01:00.0  On |                  N/A |
| 34%   43C    P8     1W /  30W |    489MiB /  1993MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               

到此,你已经成功安装nvidia docker 2.0, 当然你还需要进一步的设置,以便完成实际的工作。

Enjoy, have a lot of fun!