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.

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:
$ 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:
$ 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:
$ 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:
$ 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.
Make sure you have installed the NVIDIA driver and Docker 20.10 for your Linux distribution.
You do not need to install the CUDA toolkit on the host, but the driver needs to be installed.
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.
Add the package repositories:
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) $ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ $ curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
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
Restart the Docker service:
$ sudo systemctl restart docker
Single GPU
#### Test nvidia-smi with the latest official CUDA image
sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
Multiple GPUs
#### Test nvidia-smi with the latest official CUDA image on two GPUs
sudo docker run --rm --runtime=nvidia --gpus 2 nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
This test should output nvidia-smi information. Additional information on advance configuration can be found here.