docker中使用GPU

在前面配置了docker安装tensorr,本片记录一下在docker中调用gpu。首先我们需要安装docker>=19.03以上版本。

查看自己docker版本
sudo docker --version

若需要升级,按照如下方式:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
    stable"
sudo apt-get update
查看docker有那些版本
apt-cache madison docker-c
然后选择版本升级
sudo apt-get install docker-ce=5:19.03.15~3-0~ubuntu-xenial
然后重新启动docker
sudo systemctl start docker

docker 安装好后,直接来安装nvidia-docker 操作如下

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.lis
sudo apt-get update
sudo apt-get install nvidia-docker
重启docker
sudo systemctl restart docker

最后安装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 systemctl restart docke

进入docker测试

sudo docker run -it --gpus all --shm-size 20g nvidia/cuda:11.4.0-cudnn8-devel-ubuntu18.04 /bin/bash

docker中使用GPU_第1张图片
以上就完成了docker调用gpu

你可能感兴趣的:(docker,docker,容器,linux)