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

To use GPU within the Docker container, we need nvidia-docker. (Sik-Ho Tsang @ Medium)

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.0, another 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

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 | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L$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 pulled, nvcc — version is called and the cuda version is shown.

It seems successful! :)


About nvidia-docker Version 2.0

nvidia-docker Installation (version 2.0)

Using NVIDIA GPU within Docker Containers

安裝 NVIDIA Docker 2 來讓容器使用 GPU




PhD, Researcher. I share what I've learnt and done. :) My LinkedIn:, My Paper Reading List:

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Trident: Pool 1 — Constant Product Pool

API design fundamentals: do the evolution

Mana Engine: Working with Components

Migrating from bare metal machines to AWS ECS

Sprites and Sound for the commodore 64 (part 1)

Why GPT-3 is a good product, not just a groundbreaking model

Readings: Week of October 20th

Union of 4PL, Control tower and Integration transforming Logistics Eco-system

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sik-Ho Tsang

Sik-Ho Tsang

PhD, Researcher. I share what I've learnt and done. :) My LinkedIn:, My Paper Reading List:

More from Medium

Tutorial: Docker Installation in WSL 2 of Windows

Getting started with custom NVIDIA Deepstream 6.0 pipelines in Python

Object Detection in 5 mins

Obstruction detection and tracking using OpenCV-Python