Installing Docker and The Docker Utility Engine for NVIDIA GPUs

The NVIDIA Container Toolkit allows users to build and run GPU accelerated Docker containers. The toolkit includes a container runtime library and utilities to configure containers to leverage NVIDIA GPUs automatically. Complete documentation and frequently asked questions are available on the repository wiki.

../_images/dg-docker-01.png

Installing Docker

First you will need to set up the repository.

Update the apt package index with the command below:

$ sudo apt-get update

Install packages to allow apt to use a repository over HTTPS:

1
2
3
4
5
6
$ sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Next you will need to add Docker’s official GPG key with the command below:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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:

1
2
3
4
5
6
$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
    9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Use the following command to set up the stable repository:

1
2
3
4
5
6
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

Install Docker Engine - Community Update the apt package index:
$ sudo apt-get update

Install Docker Engine 19.03.12:

$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io

Verify that Docker Engine - Community is installed correctly by running the hello-world image:

$ sudo docker run hello-world

More information on how to install Docker can be found here.

Enabling the Docker Repository and Installing the NVIDIA Container Toolkit

Make sure you have installed the NVIDIA driver and Docker 20.10 for your Linux distribution.

Note

You do not need to install the CUDA toolkit on the host, but the driver needs to be installed.

Note

With the release of Docker 19.03, usage of nvidia-docker2 packages is deprecated since NVIDIA GPUs are now natively supported as devices in the Docker runtime.

For first-time users of Docker 20.10 and GPUs, continue with the instructions for getting started below.

  1. Add the package repositories:

    1
    2
    3
    $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    $ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
    $ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
    
  2. Download information from all configured sources about the latest versions of the packages and install the nvidia-container-toolkit package:

    $ sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
    
  3. Restart the Docker service:

    $ sudo systemctl restart docker
    

Testing Docker and NVIDIA Container Runtime

Single GPU

1
2
#### Test nvidia-smi with the latest official CUDA image
$ sudo docker run --gpus all nvidia/cuda:11.0-base nvidia-smi

Multiple GPUs

1
2
#### Test nvidia-smi with the latest official CUDA image on two GPUs
$ sudo docker run --gpus 2 nvidia/cuda:11.0-base nvidia-smi

This test should output nvidia-smi information. Additional information on advance configuration can be found here.