Machine Growth
Published in

Machine Growth

Nvidia-Docker 2.0, Cudnn 7.0, Tensorflow 2.2 Installation & docker image creation

This blog will walk you through the installation of Nvidia-Docker, Cuddnn and tensorflow. After the installation, you could save all the installed packages and libraries by creating a new docker image.

If you see this error “ImportError:” after Nvidia-Docker is installed, you may skip to “Cudnn Installation” section.

  • Nvidia-Docker installation

Remove previous version of nvidia-docker.

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

Get the nvidia-docker list.

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.listsudo apt-get update

Install nvidia-docker2

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

Once you have installed nvidia-docker, you can pull the image with cuda and instantiate a container.

docker run --runtime=nvidia --rm nvidia/cuda:10.1-devel /bin/bash
  • Cudnn Installation

But this image does not contain cudnn7.0 and python. We have to install these package.

apt-get update
apt-get install python3.6
apt install python3-pip
pip3 install --upgrade pip
wget dpkg -i nvidia-machine-learning-repo-ubuntu1804_1.0.0–1_amd64.debsudo apt update
sudo apt install -y libcudnn7 libcudnn7-dev libnccl2 libc-ares-dev
sudo apt autoremove
sudo mkdir -p /usr/local/cuda-10.1/nccl/libsudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/local/cuda-10.1/nccl/lib/sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/local/cuda-10.1/lib64/
  • Tensorflow 2.2 Installation

Install latest version (2.2 currently) of tensorflow

pip install tensorflow

Test your tensorflow running on gpu

import tensorflow as tf

You will see “True” showing that Tensorflow now is capable of using GPU.

  • Docker Image Creation

Since you have installed all the required libraries and you do not want to repeat the steps again. You can create image for the container.

Do not close your current command prompt. Open a new command prompt and follow these steps.

sudo docker ps
docker commit _REPLACE_THIS_WITH_YOUR CONTAINER_ID_HAVING_TENSORFLOW_2_2_cuda_10_1_cuddn_7_tf_2_2:0

After that, you can create container with all the libraries just by using a single line

nvidia-docker run -it cuda_10_1_cuddn_7_tf_2_2:0 /bin/bash



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