docker-ce和nvidia-docker安装
写在最前面
**本篇文章主要介绍如何安装docker和可以使用GPU的nvidia-docker,
只针对Linux系统安装,windows系统安装此处没有介绍。**
安装的版本docker-ce和nvidia-docker2.0。
ubuntu下安装docker
首先,该教程讲述的是docker-ce的安装,如果想要安装docker.io的话,可以看下我的另外一篇博客:
[docker.io安装](https://blog.csdn.net/weixin_41383736/article/details/84399197)
言归正传:
移除旧版本的docker和docker.io:
apt-get remove docker docker-engine docker.io
然后,使用apt-get安装系统工具
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
安装GPG证书:
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
写入软件源信息:
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
然后更新apt-get并且安装docker-ce:
sudo apt-get -y update
sudo apt-get -y install docker-ce
到此docker-ce安装成功
centos安装docker
安装必要的一些系统工具:
yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker- ce/linux/centos/docker-ce.repo
更新并安装 Docker-CE:
yum makecache fast
yum -y install docker-ce
开启Docker服务:
service docker start
docker-ce安装成功验证:
ubuntu下安装nvidia-docker
# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
setp1:
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
setp2:
sudo apt-get purge -y nvidia-docker
#Add the package repositories
setp3:
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -
setp4:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
setp5:
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list
step6:
sudo apt-get update
#Install nvidia-docker2 and reload the Docker daemon configuration
step7:
sudo apt-get install -y nvidia-docker2
sudo systemctl daemon-reload
sudo systemctl restart docker
#Test nvidia-smi with the latest official CUDA image
step8(这一步是下载cuda的镜像测试nvidia-docker是否安装成功,
很慢,如果不想等的话可以直接跳过执行下一步验证):
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
step9:
执行nvidia-docker version查看版本
centos安装nvidia-docker
#If you are not using the official docker-ce package on CentOS/RHEL, use the next section.
#If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
step1:
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo yum remove nvidia-docker
#Add the package repositories
step2:
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
#Install nvidia-docker2 and reload the Docker daemon configuration
step3(如果安装到这一步出现问题,跳过第四步去看解决方法):
sudo yum install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
#Test nvidia-smi with the latest official CUDA image
step4(这个和ubuntu那个版本最后一步的介绍是一样的):
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
解决方法:
#If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo yum remove nvidia-docker
#Add the package repositories
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
#Install the nvidia runtime hook
sudo yum install -y nvidia-container-runtime-hook
#Test nvidia-smi with the latest official CUDA image
#You can't use `--runtime=nvidia` with this setup.
docker run --rm nvidia/cuda:9.0-base nvidia-smi
最后验证方法同ubuntu版本的nvidia-docker verison。