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。