前言
想让在docker中使用GPU资源,有两个选择
1.安装nvidia-docker toolkit
2.安装nvidaia-docker2
1. 安装nvidia-docker toolkit
使用nvidia-container-toolkit的最大优点:linux主机不需要安装 CUDA toolkit,仅安装显卡驱动 cuda-drivers 即可
安装nvidia-container-toolkit,后添加—gpus参数来使用
Ubuntu 16.04/18.04, Debian Jessie/Stretch/Buster:
# Add the package repositories
$ 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
$ sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
$ sudo systemctl restart docker
CentOS 7 (docker-ce), RHEL 7.4/7.5 (docker-ce), Amazon Linux 1/2
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
$ sudo yum install -y nvidia-container-toolkit
$ sudo systemctl restart docker
测试安装是否成功
1. 查看–gpus 参数是否安装成功:
$ docker run --help | grep -i gpus
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
2. 运行nvidia官网提供的镜像,并输入nvidia-smi命令,查看nvidia界面是否能够启动:
docker run --gpus all nvidia/cuda:9.0-base nvidia-smi
2. 安装nvidia-docker2
前提,已经安装了docker
在一台联网的机器上执行下面命令
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
yum install --downloadonly nvidia-docker2 --downloaddir=/tmp/nvidia
会得到libnvidia-container、libnvidia-container-tools、nvidia-container-runtime、nvidia-container-toolkit、nvidia-docker2
上传到离线环境中,进入rpm包路径里执行
rpm -Uvh *.rpm --nodeps --force
3. 离线安装nvidia-container-runtime
docker19.03之后,不再需要安装nvidia-docker了。只安装NVIDIA-CONTAINER-RUNTIME就可以使用了,并且支持docker-compose。
参考链接:
https://blog.csdn.net/ace1231/article/details/119697280