The NVIDIA Container Toolkit is a set of tools and libraries that enable GPU-accelerated Docker containers. It allows you to leverage NVIDIA GPUs within containers by providing the necessary drivers and runtime components. This toolkit is essential for running CUDA applications, machine learning workloads, and other GPU-accelerated tasks in Docker containers.
Nvidia-Docker2: This package was the original way to enable GPU support in Docker containers. It included the necessary runtime components and configurations to integrate NVIDIA GPUs with Docker. However, it has been deprecated in favor of the more flexible nvidia-container-toolkit.
Nvidia-Container-Toolkit: This is the current and recommended way to enable NVIDIA GPU support in Docker containers. It is more modular and decouples the runtime from the Docker package, allowing for greater flexibility and easier updates. This toolkit allows you to use the --gpus flag in Docker to specify GPU resources.
NVIDIA GPU Support: Access NVIDIA GPUs from within Docker containers.
CUDA Toolkit Integration: Provides necessary components to run CUDA applications.
Compatibility: Works with different versions of Docker and various NVIDIA GPUs.
CUDA-capable GPU: Ensure you have an NVIDIA GPU installed.
Docker: Docker must be installed on your system. You can install Docker by following the official guide here.
NVIDIA Driver: Ensure that the appropriate NVIDIA driver is installed on your system. You can check the installation with the following command: nvidia-smi.
$ 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/stable/deb/nvidia-container-toolkit.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
$ sudo apt-get update
$ sudo apt-get install -y nvidia-container-toolkit
$ sudo nvidia-ctk runtime configure --runtime=docker
The nvidia-ctk command modifies the /etc/docker/daemon.json file on the host. The file is updated so that Docker can use the NVIDIA Container Runtime.
$ sudo systemctl restart docker
Run a test container:
$ sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi $ sudo docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubuntu22.04 nvidia-smi
This command should output information about your GPU, confirming that the container has access to the GPU.