Installing Docker and The Docker Utility Engine for NVIDIA GPUs

NVIDIA AI Enterprise 2.0 or later

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.

dg-docker-01.png

First you will need to set up the repository.

Update the apt package index with the command below:

Copy
Copied!
            

$ sudo apt-get update

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

Copy
Copied!
            

$ 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:

Copy
Copied!
            

$ 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:

Copy
Copied!
            

$ 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:

Copy
Copied!
            

$ 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:

Copy
Copied!
            

$ sudo apt-get update

Install Docker Engine:

Please refer to Install Docker Engine on Ubuntu | Docker Documentation for a current installation procedure for Ubuntu.

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

Copy
Copied!
            

$ 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.

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:

    Copy
    Copied!
                

    $ 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


  2. Download information from all configured sources about the latest versions of the packages and install the nvidia-container-toolkit package:

    Copy
    Copied!
                

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


  3. Restart the Docker service:

    Copy
    Copied!
                

    $ sudo systemctl restart docker


Single GPU

Copy
Copied!
            

#### 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

Copy
Copied!
            

#### Test nvidia-smi with the latest official CUDA image on two GPUs sudo docker run --rm --runtime=nvidia --2 all 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.

© Copyright 2022-2023, NVIDIA. Last updated on Sep 11, 2023.