【TensorFlow 2 gpu 安装】步骤2 - ubuntu 20.04 安装 NVIDIA Container Toolkit Nvidia Docker 2

安装好doker之后,继续安装 NVIDIA Container Toolkit
官方安装介绍:https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html

设置Docker

curl https://get.docker.com | sh \
  && sudo systemctl start docker \
  && sudo systemctl enable docker

设置 NVIDIA Container Toolkit

官方代码:

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

可能出现两个问题:

gpg: 找不到有效的 OpenPGP (源于指令:curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -)

E: 无法定位软件包 nvidia-docker2 (源于指令:curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list)

需要把ip地址写入host文件中!!

sudo vi /etc/hosts

复制以下ip到host中

185.199.108.153 nvidia.github.io
185.199.109.153 nvidia.github.io
185.199.110.153 nvidia.github.io
185.199.111.153 nvidia.github.io

重复官方代码即可

安装 nvidia docker2

sudo apt-get update
sudo apt-get install -y nvidia-docker2

重启docker

sudo systemctl restart docker

测试

sudo docker run --gpus all --rm nvidia/cuda nvidia-smi

让 Docker 使用运行镜像(如果没有就下载),创建一个容器。并在容器中运行 nvidia-smi 命令。–rm: 运行结束后,删除容器
结果为:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            On   | 00000000:00:1E.0 Off |                    0 |
| N/A   34C    P8     9W /  70W |      0MiB / 15109MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

你可能感兴趣的:(TensorFlow,docker,tensorflow,nvidia)