docker19.03使用NVIDIA显卡
前言
使用gpu错误:docker: Error response from daemon: could not select device driver “” with ...具体解决方案在下面有.
2019年7月的docker 19.03已经正式发布了,这次发布对我来说有两大亮点。
1,就是docker不需要root权限来启动喝运行了
2,就是支持GPU的增强功能,我们在docker里面想读取nvidia显卡再也不需要额外的安装nvidia-docker了
安装nvidia驱动
确认已检测到NVIDIA卡:
lspci -vv | grep -i nvidia
这里不再详细介绍:如果不知道请移步https://blog.csdn.net/BigData_Mining/article/details/99670642
安装NVIDIA Container Runtime
$ cat nvidia-container-runtime-script.sh
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey |
sudo apt-key add -
distribution=$(. /etc/os-release;echo
I
D
ID
IDVERSION_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
执行脚本
sh nvidia-container-runtime-script.sh
OK
deb https://nvidia.github.io/libnvidia-container/ubuntu18.04/
(
A
R
C
H
)
/
d
e
b
h
t
t
p
s
:
/
/
n
v
i
d
i
a
.
g
i
t
h
u
b
.
i
o
/
n
v
i
d
i
a
−
c
o
n
t
a
i
n
e
r
−
r
u
n
t
i
m
e
/
u
b
u
n
t
u
18.04
/
(ARCH) / deb https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/
(ARCH)/debhttps://nvidia.github.io/nvidia−container−runtime/ubuntu18.04/(ARCH) /
Hit:1 http://archive.canonical.com/ubuntu bionic InRelease
Get:2 https://nvidia.github.io/libnvidia-container/ubuntu18.04/amd64 InRelease [1139 B]
Get:3 https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/amd64 InRelease [1136 B]
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
Get:5 https://nvidia.github.io/libnvidia-container/ubuntu18.04/amd64 Packages [4076 B]
Get:6 https://nvidia.github.io/nvidia-container-runtime/ubuntu18.04/amd64 Packages [3084 B]
Hit:7 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic InRelease
Hit:8 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:9 http://us-east4-c.gce.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 9435 B in 1s (17.8 kB/s)
Reading package lists… Done
安装:
$ apt-get install nvidia-container-runtime
查看:
which nvidia-container-runtime-hook
/usr/bin/nvidia-container-runtime-hook
安装docker-19.03
step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
Step 2: 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Step 3: 更新并安装 Docker-CE
yum makecache fast
yum -y install docker-ce-19.03.2
Step 4: 开启Docker服务
systemctl start docker && systemctl enable docker
验证docker版本是否安装正常
$ docker version
Client: Docker Engine - Community
Version: 19.03.2
API version: 1.40
Go version: go1.12.8
Git commit: 6a30dfc
Built: Thu Aug 29 05:28:55 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.2
API version: 1.40 (minimum version 1.12)
Go version: go1.12.8
Git commit: 6a30dfc
Built: Thu Aug 29 05:27:34 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683
验证下-gpus选项
$ docker run --help | grep -i gpus
–gpus gpu-request GPU devices to add to the container (‘all’ to pass all GPUs)
运行利用GPU的Ubuntu容器
$ docker run -it --rm --gpus all ubuntu nvidia-smi
故障排除
您是否遇到以下错误消息:
$ docker run -it --rm --gpus all debian
docker: Error response from daemon: linux runtime spec devices: could not select device driver “” with capabilities: [[gpu]].
上述错误意味着Nvidia无法正确注册Docker。它实际上意味着驱动程序未正确安装在主机上。这也可能意味着安装了nvidia容器工具而无需重新启动docker守护程序:您需要重新启动docker守护程序。
我建议你回去验证是否安装了nvidia-container-runtime或者重新启动Docker守护进程。
列出GPU设备
$ docker run -it --rm --gpus all ubuntu nvidia-smi -L
$ docker run -it --rm --gpus all ubuntu nvidia-smi --query-gpu=index,name,uuid,serial --format=csv