Docker 19.03,增加了对--gpus选项的支持,我们在docker里面想读取nvidia显卡再也不需要额外的安装nvidia-docker了,下面开始实战
1. 安装nvidia-container-runtime:
查看官网(https://nvidia.github.io/nvidia-container-runtime)得知基于RHEL的发行版添加源的方式为:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.repo | \
sudo tee /etc/yum.repos.d/nvidia-container-runtime.repo
添加源后直接yum安装:
yum install nvidia-container-runtime
2. 安装docker-19.03
在新主机上首次安装Docker Engine-Community之前,需要设置Docker存储库。之后,您可以从存储库安装和更新Docker。
- 2.1 安装所需的软件包。yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序。
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
- 2.2 使用以下命令来设置稳定的存储库。
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 2.3 开启Docker服务
systemctl start docker && systemctl enable docker
- 2.4 验证docker版本是否安装正常
$ docker version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:58:10 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.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
3. 启动容器
docker run -d -it -p 1518:1518 --name="centos" --gpus all nvidia/cuda:9.1-cudnn7-runtime-centos7 /bin/bash
进入容器
docker exec -it centos /bin/bash
查看显卡
$ nvidia-smi
Mon Oct 21 02:15:19 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.59 Driver Version: 390.59 |
|-------------------------------+----------------------+----------------------+
| 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 GTX 108... Off | 00000000:00:08.0 Off | N/A |
| 29% 33C P0 58W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX 108... Off | 00000000:00:09.0 Off | N/A |
| 29% 28C P5 12W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 GeForce GTX 108... Off | 00000000:00:0A.0 Off | N/A |
| 29% 27C P5 12W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 3 GeForce GTX 108... Off | 00000000:00:0B.0 Off | N/A |
| 29% 30C P5 12W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 4 GeForce GTX 108... Off | 00000000:00:0C.0 Off | N/A |
| 29% 31C P0 58W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 5 GeForce GTX 108... Off | 00000000:00:0D.0 Off | N/A |
| 29% 23C P5 12W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 6 GeForce GTX 108... Off | 00000000:00:0E.0 Off | N/A |
| 29% 27C P5 12W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 7 GeForce GTX 108... Off | 00000000:00:0F.0 Off | N/A |
| 29% 27C P5 12W / 250W | 0MiB / 11178MiB | 3% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+