1)
2)
NVIDIA 容器工具包允许用户构建和运行 GPU 加速的 Docker 容器。该工具包包括一个容器运行时库和实用程序,可自动配置容器以利用 NVIDIA GPU。
安装container toolkit教程:(ubuntu18.10会特有的问题见下面的帖子)
Installation Guide — NVIDIA Cloud Native Technologies documentation
1解决 Ubuntu18.10 无法安装 Nvidia-docker2_吴中骊的博客-CSDN博客_ubuntu无法安装docker
测试nvidia container toolkit安装成功
sudo docker run --rm --gpus all nvidia/cuda:8.0-cudnn6-devel-ubuntu16.04 nvidia-smi
3)做一个含cuda和cudnn的image
4)运行image为容器
--gpus flag (as explained in the link above)docker run --gpus all -it -d --name py0331 pytorch:latest /bin/bash
验证pytorch已经支持gpu加速:
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import torch
- >>> torch.cuda.is_available()
- True
- >>> torch.cuda.device_count()
- 1
- >>> torch.cuda.current_device()
- 0
- >>> torch.cuda.get_device_name(0)
- 'GeForce GTX 1080 Ti'
- >>> quit()