The cart is empty

Computational tasks requiring Graphics Processing Units (GPUs) are increasingly common, particularly in fields like machine learning, deep learning, and image processing. Containerizing applications that perform these tasks offers many benefits, including dependency isolation, portability, and scalability. In this article, we will discuss how to create and manage GPU-supported containerized applications on the CentOS 7 operating system.

Prerequisites

  • A running CentOS 7 installation.
  • A NVIDIA-compatible Graphics Card (GPU) with NVIDIA drivers installed.
  • Docker installed, version 19.03 or newer, which supports NVIDIA Container Toolkit.

Installing Docker and NVIDIA Container Toolkit

  1. Installing Docker: First, install Docker using the following commands:

    sudo yum install -y yum-utils
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    sudo yum install docker-ce docker-ce-cli containerd.io
    sudo systemctl start docker && sudo systemctl enable docker
    
  2. Installing NVIDIA Docker support: The NVIDIA Container Toolkit allows Docker to utilize the GPU. To install it, execute:

    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
    sudo yum install -y nvidia-container-toolkit
    sudo systemctl restart docker
    

Creating a Dockerfile with GPU Support Create a Dockerfile that enables your application to utilize the GPU. It can be based on an image that already contains the necessary libraries for GPU work, such as nvidia/cuda. Example Dockerfile:

FROM nvidia/cuda:11.0-base
CMD nvidia-smi

This simple Dockerfile uses the CUDA image as a base and tests the setup by running the nvidia-smi command, which displays information about the available GPUs.

Building and Running the Container After creating the Dockerfile, build the image with the command:

docker build -t gpu-app .

And run the container with access to the GPU:

docker run --gpus all gpu-app

This command runs the container and enables it to access all available GPUs.

Application Management

To manage applications with GPU support, it's important to monitor GPU resource utilization and optimize your application's performance. Use tools like NVIDIA-smi and DCGM (Data Center GPU Manager) for monitoring and diagnostics.

Security and Updates

Ensure that your system and all containers are regularly updated to maintain security. Follow security advisories and recommendations from Docker and NVIDIA.

Containerizing GPU-supported applications on CentOS 7 allows for efficient utilization of hardware resources, dependency isolation, and easy portability. By following the steps outlined in this article, you can create and manage these applications to make the most efficient use of available GPU resources.