当前位置: 首页 > 工具软件 > nvidia-docker > 使用案例 >

Ubuntu18.04下docker+NVIDIA-docker2指定版本安装

井高峯
2023-12-01

1 . $ sudo apt update(安装docker时报错找不到docker, 使用sudo apt-get update)
2 . $ sudo apt install apt-transport-https ca-certificates curl software-properties-common

3 . 在/etc/apt/sources.list.d/docker.list文件中添加如下文本

deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable

4 .  添加阿里秘钥,可以添加官方秘钥和阿里秘钥

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -   // 官方
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -  // 阿里


添加完毕后使用如下命令验证:

sudo apt-key fingerprint 0EBFCD88

 

正常情况下结果如下:

sudo: /etc/sudoers.d is world writable
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

5 . docker安装

想要安装指定版本,直接安装docker-ce会有版本的问题,可以通过以下命令分别进行安装:

apt-cache madison docker-ce-cli

sudo apt-get install docker-ce-cli=版本号

apt-cache madison containerd

sudo apt-get install containerd=版本号

apt-cache madison docker-ce

sudo apt-get install docker-ce=版本号

 

查看是否安装成功使用以下命令:

docker --version

ubuntu@computer:~$ docker --version
Docker version 19.03.0, build aeac949

sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

结果如上则安装成功

设置开机启动docker
sudo systemctl enable docker
重启docker,使设置生效
sudo systemctl restart docker

6 . NVIDIA-docker2安装

# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
sudo docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker
sudo apt autoremove
 
# Add the package repositories
# command 1
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
 
# command 2
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
 
# command 3
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
 
# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
 
# Test nvidia-smi with the latest official CUDA image
sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

如果上面最后一条命令失败,可以使用如下验证:

sudo docker run --runtime=nvidia --rm nvidia/cuda:11.0-base nvidia-smi

7 . NVIDIA Container Runtime安装

sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list
sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sudo apt-get install nvidia-container-runtime

测试下

sudo docker run -it --rm --gpus all ubuntu nvidia-smi

最后重启下docker

sudo systemctl restart docker

11.0是我安装的cuda版本号,自己cuda版本查询可以使用nvcc -V,安装成功则输出如下内容

sudo: /etc/sudoers.d is world writable
Wed Apr 21 07:12:52 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.38       Driver Version: 455.38       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  GeForce RTX 208...  Off  | 00000000:01:00.0  On |                  N/A |
| 27%   34C    P8    12W / 260W |    309MiB / 11016MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

 

 类似资料: