[4] 服务器docker安装、测试

接上一步nccl+caffe源码编译,继续安装docker

首先删除旧版docker
sudo apt-get remove docker docker-engine docker.io
然后更新下
sudo apt-get update
添加CA证书以及HTTPS软件包

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加密钥
curl -fsSL [https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg](https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg) | sudo apt-key add -

添加docker源

sudo add-apt-repository \
"deb [arch=amd64] [https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu](https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu) \
$(lsb_release -cs) \
stable"

安装docker ce
sudo apt-get update
sudo apt-get install docker-ce

测试
sudo docker version
或者
sudo docker run hello-world

Nvidia-docker

根据nvidia-docker步骤

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
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 nvidia-docker2

但是,这样有可能出出错

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package nvidia-docker2

解决办法如下,参考网址

LOCALDIR=/var/lib/nvidia-docker-repo

sudo mkdir -p $LOCALDIR && cd $LOCALDIR
sudo git clone -b gh-pages https://github.com/NVIDIA/libnvidia-container.git
sudo git clone -b gh-pages https://github.com/NVIDIA/nvidia-container-runtime.git
sudo git clone -b gh-pages https://github.com/NVIDIA/nvidia-docker.git

sudo tee /etc/apt/sources.list.d/nvidia-docker.list <<< \
"deb file://$LOCALDIR/libnvidia-container/ubuntu14.04/amd64 /
deb file://$LOCALDIR/nvidia-container-runtime/ubuntu14.04/amd64 /
deb file://$LOCALDIR/nvidia-docker/ubuntu14.04/amd64 /"

sudo apt-key add $LOCALDIR/nvidia-docker/gpgkey
sudo apt-get update

或者修改之前的

curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu14.04/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list

当出现

deb https://nvidia.github.io/libnvidia-container/ubuntu14.04/$(ARCH) /
deb https://nvidia.github.io/nvidia-container-runtime/ubuntu14.04/$(ARCH) /
deb https://nvidia.github.io/nvidia-docker/ubuntu14.04/$(ARCH) /

表明可用,这之前可以试试
https://nvidia.github.io/nvidia-docker/ubuntu14.04/nvidia-docker.list
https://nvidia.github.io/nvidia-docker/ubuntu16.04/nvidia-docker.list

还有可能提示如下的错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nvidia-docker2 : Depends: docker-ce (= 18.06.2~ce~3-0~ubuntu) but 18.06.3~ce~3-0~ubuntu is to be installed or
                           docker-ee (= 18.06.2~ee~3-0~ubuntu) but it is not installable
E: Unable to correct problems, you have held broken packages.

这是docker版本和需要的版本不符合,按照提示安装对应的版本即可
sudo apt-get install docker-ce=18.06.2~ce~3-0~ubuntu

然后再安装
sudo apt-get install nvidia-docker2就行了。

你可能感兴趣的:([4] 服务器docker安装、测试)