Justus Nithushan
2 min readDec 24, 2018

Nvidia-Docker2 installation procedure in ubuntu16.04

Before we start…

We need nvidia docker to use gpu within docker container. There are few steps to be followed for the sucessfull installation of nvidia-docker2.

This story explains how to install nvidia docker from the very begining. If your machine has docker installed skip step-1 and step-2.

If you have already installed nvidia-docker1, It need to be removed. So, follow the following command to remove nvidia-docker 1.0

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 -y nvidia-docker

lets get started…

Step-1: Set the docker repository and update.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”sudo apt-get update

Step-2: Make sure you are about to install from the Docker repository

apt-cache policy docker-ce

Step-3: Set nvidia-docker repository and update.

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

Step-4: Install nvidia-docker2.

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

Step-5 : Install nvidia driver. As I am using ubuntu 16.04 lets install the latest nvidia-375. For further details check the reference section below

sudo apt install nvidia-375 nvidia-settings

Step-6 : Run nvidia-smi with cuda image and check whether it recognizes the GPU

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

Hope you have installed nvidia-docker2 successfully.

References

About nvidia-docker2

About nvidia drivers

https://gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07

About docker

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

No responses yet