Ubuntu18.04安装docker-ce、显卡驱动、以及nvidia-docker

目录:

1、安装Docker-ce
2、安装显卡驱动
3、安装nvidia-docker

一、安装Docker-ce

方法一:
使用官方脚本自动安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

方法二:参考以前写过的文章:
https://www.jianshu.com/p/42d1c9fb538c

二、安装显卡驱动:

①安装前进行环境准备:

  1. 禁用nouveau,创建文件,并添加如下内容
sudo vim /etc/modprobe.d/blacklist-nouveau.conf

添加如下内容:

blacklist nouveau
options nouveau modeset=0

执行如下命令使禁用生效,并重启

sudo update-initramfs -u
sudo reboot
lsmod | grep nouveau ##重启后验证是否生效

②安装显卡

1、先查看显卡型号:

ubuntu:~$ lspci | grep -i 3d
06:00.0 3D controller: NVIDIA Corporation GK210GL [Tesla K80] (rev a1)
07:00.0 3D controller: NVIDIA Corporation GK210GL [Tesla K80] (rev a1)
84:00.0 3D controller: NVIDIA Corporation GK210GL [Tesla K80] (rev a1)
85:00.0 3D controller: NVIDIA Corporation GK210GL [Tesla K80] (rev a1)

2、到英伟达官网https://www.nvidia.cn/Download/index.aspx?lang=cn
查找对应的显卡型号,并进行下载:
3、获取对应的run,并添加执行权限,运行安装:

ubuntu@ubuntu:/tmp$ chmod +x NVIDIA-Linux-x86_64-418.67.run && sudo sh NVIDIA-Linux-x86_64-418.67.run

ps:在安装的过程中,如果遇到gcc、make等环境不存在,退出并进行环境安装:sudo apt install gcc && sudo apt install make等等

4、安装后,即可查看是否安装成功:

ubuntu@ubuntu:/home$ nvidia-smi 
Mon Aug  5 09:20:30 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.67       Driver Version: 418.67       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:06:00.0 Off |                    0 |
| N/A   41C    P0    60W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:07:00.0 Off |                    0 |
| N/A   38C    P0    82W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:84:00.0 Off |                    0 |
| N/A   42C    P0    64W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:85:00.0 Off |                    0 |
| N/A   37C    P0    84W / 149W |      0MiB / 11441MiB |     97%      Default |
+-------------------------------+----------------------+----------------------+

三、安装nvidia-docker2

1、 获取gpg密钥并添加密钥

$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -

2、 定义变量distribution,等于变量$(...),值为 ubuntu18.04

$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

3、获取ubuntu18.04版本的nvidia-docker列表,结果返回给标准输出,tee命令读取标准输入的数据(即上一条curl命令的输出),并将内容输出成文件,并且在屏幕上显示

$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list

4、更新源并安装nvidia-docker2

$ sudo apt-get update &&  sudo apt-get install nvidia-docker2

5、重新加载docker守护进程配置
$ sudo pkill -SIGHUP dockerd
6、验证是否成功安装:

$ sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
ubuntu@ubuntu:/home$ sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
[sudo] password for ubuntu: 
Mon Aug  5 09:26:32 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.67       Driver Version: 418.67       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:06:00.0 Off |                    0 |
| N/A   42C    P0    60W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:07:00.0 Off |                    0 |
| N/A   39C    P0    83W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:84:00.0 Off |                    0 |
| N/A   43C    P0    64W / 149W |      0MiB / 11441MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:85:00.0 Off |                    0 |
| N/A   37C    P0    84W / 149W |      0MiB / 11441MiB |     99%      Default |
+-------------------------------+----------------------+----------------------+

参考如下链接:
https://blog.csdn.net/qxqxqzzz/article/details/89706628
https://blog.csdn.net/new_delete_/article/details/81544438

你可能感兴趣的:(Ubuntu18.04安装docker-ce、显卡驱动、以及nvidia-docker)