欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu18.04安装nvidia-docker(亲测有效,步骤详尽)

程序员文章站 2022-03-30 13:47:55
...

Ubuntu 18.04安装NVIDIA-docker

0.前提: 
  (1)首先安装docker;具体步骤:https://blog.csdn.net/BigData_Mining/article/details/87868711
  (2)安装Nvidia驱动,CUDA和CUDNN;具体步骤:https://blog.csdn.net/BigData_Mining/article/details/99670642
1.然后执行下面的步骤:

$curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
$curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu18.04/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$sudo apt-get update

2.安装nvidia-docker2软件包并重新加载docker守护程序配置

$sudo apt-get install nvidia-docker2
$sudo pkill -SIGHUP dockerd
$docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

[注]:运行上一步若报错:

[email protected]:~$ sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
docker: Error response from daemon: Unknown runtime specified nvidia.
See 'docker run --help'.

当显卡驱动安装好的前提下(用指令$nvidia-smi来显示显卡驱动),则换成运行下步,指定安装的cuda版本:

$sudo nvidia-docker run --rm nvidia/cuda:10.1-devel nvidia-smi
[email protected]:~$ sudo nvidia-docker run --rm nvidia/cuda:10.1-devel | nvidia-smi
Fri Aug 16 16:30:02 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.26       Driver Version: 430.26       CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       Off  | 00000000:3C:00.0 Off |                  N/A |
| N/A   52C    P0    N/A /  N/A |    239MiB /  2004MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3038      G   /usr/lib/xorg/Xorg                           121MiB |
|    0      4709      G   /usr/bin/gnome-shell                         109MiB |
|    0     18218      G   /usr/lib/firefox/firefox                       1MiB |
|    0     18402      G   /usr/lib/firefox/firefox                       1MiB |
|    0     18463      G   /usr/lib/firefox/firefox                       1MiB |
+-----------------------------------------------------------------------------+
Unable to find image 'nvidia/cuda:10.1-devel' locally
10.1-devel: Pulling from nvidia/cuda
7413c47ba209: Pulling fs layer
0fe7e7cbb2e8: Pulling fs layer
1d425c982345: Pulling fs layer
344da5c95cec: Pulling fs layer
43bcc41986db: Pulling fs layer
76661327d908: Pulling fs layer
abdc887b90e5: Pulling fs layer
eb38470de0e2: Pulling fs layer
0adb8d7f107f: Pulling fs layer

表示成功了!