错误-显然是源仓库的版本不对-切记不要把16.04的源用在18.04的系统里:

nvidia-docker2 : Depends: docker-ce (= 5:18.09.3~3-0~ubuntu-xenial) but 5:18.09.3~3-0~ubuntu-bionic is to be installed or docker-ee (= 5:18.09.3~3-0~ubuntu-xenial) but it is not installable

解决:Docker Tutorial 5: Nvidia-Docker 2.0 Installation in Ubuntu 18.04

Differences between 1.0 and 2.0

When I decided to install nvidia-docker 2.0, I’ve just found most of the tutorials are talking about 1.0, and not much detailed tutorial for 2.0.

Before talking about the installation of nvidia-docker 2.0, I would like to mention about the difference between 1.0 and 2.0 first.

In the past, when we were using 1.0another nvidia-docker daemon was used to replace docker to run the GPU image. And right now, with 2.0, we do not need to replace docker. Instead, we can choose to enable nvidia-docker at runtime in the command.

To know more details about the differences, you can have a look on
https://github.com/NVIDIA/nvidia-docker/wiki/About-version-2.0

Installation Procedures

Though I followed the installation guideline from NVIDIA, I got a little bit different procedures since I cannot install nvidia-docker 2.0 at the very beginning. Let’s see how I install it.

0. If there is nvidia-docker 1.0 already, it needs to be removed. (But I do not have it.)

docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge nvidia-docker
  1. Set the repository and update. I am using Ubuntu 18.04, so I follow the Debian settings:
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

2. Install nvidia-docker 2.0 according to the guideline. However, I got “Abort” message. (It depends on computers. But if you got installation successfully, please skip steps 3–5.)

sudo apt-get install nvidia-docker2
sudo pkill -SIGHUP dockerd

I tried to run the nvidia-docker. Of course, I cannot run it because the installation is failed. I found numerous of people facing this error.

docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

3. Then I check the versions in the github:

apt-cache madison nvidia-docker2 nvidia-container-runtime

4. Since I’ve installed docker 18.03 CE (To check the docker version docker -v), I chose nvidia-docker2=2.0.3+docker18.03.1–1 for installation.

sudo apt-get install nvidia-docker2=2.0.3+docker18.03.1–1
sudo pkill -SIGHUP dockerd

5. And run the nvidia-docker 2.0 again:

docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

The nvidia image can be pulled. And we can check the GPU information by nvidia-smi.

If we try this:

sudo docker run --rm --runtime=nvidia nvidia/cuda:9.0-devel nvcc --version

After the nvidia image with cuda-9.0 is pullednvcc — version is called and the cuda version is shown.

It seems successful! :)

References

About nvidia-docker Version 2.0 
https://github.com/NVIDIA/nvidia-docker/wiki/About-version-2.0

nvidia-docker Installation (version 2.0)
https://github.com/nvidia/nvidia-docker/wiki/Installation-(version-2.0)

Using NVIDIA GPU within Docker Containers
https://marmelab.com/blog/2018/03/21/using-nvidia-gpu-within-docker-container.html

安裝 NVIDIA Docker 2 來讓容器使用 GPU
https://kairen.github.io/2018/02/17/container/docker-nvidia-install/

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐