Set up docker, nVidia drivers and TensorFlow on Ubuntu

Modified from

Configuration Steps

  1. Install Ubuntu

2. Install Nvidia Driver


sudo ubuntu-drivers autoinstall

3. Install Docker


Update the apt package index:

$ sudo apt-get update$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \

Add Docker’s official GPG key:

$ curl -fsSL | sudo apt-key add -

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88

Set up the stable repository:

$ sudo add-apt-repository \
"deb [arch=amd64] \
$(lsb_release -cs) \

Install Docker Engine:

Update the apt package index, and install the latest version of Docker Engine and containerd:

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli

4. Install NVIDIA Docker support

For NVIDIA drivers to work inside a docker, NVIDIA Docker support need to be installed in the host machine.

Add the package repositories:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L | sudo apt-key add -
curl -s -L$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

Update apt and install:

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit

Restart Docker:

sudo systemctl restart docker

Otherwise this error will show up:

5. Download and run TensorFlow docker image

Find a suitable TensorFlow docker image from and download.

$ sudo docker pull tensorflow/tensorflow:2.2.0-gpu-jupyter

Once the download is complete you can run the image with appropriate options and arguments.

$ sudo docker run -it --rm --gpus all -v $(realpath /notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:2.2.0-gpu-jupyter

The above command, on successful execution, will fire up a docker container with access to all the GPUs of the host system, /notebooks directory of the host acting as the /tf/notebooks directory of the container and 8888 ports of the host and the container bridged (Jupyter notebooks work on port 8888 by default). Now you can start a notebook by simply opening the host ip in a browser.

6. Run Jupyter notebook

Open notebook in browser:

Open the url in a browser and copy and paste the token of the jupyter instance from the terminal onto the “Password or Token” input box of the page to open the notebook.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert