How to Install Docker with ROCm GPU Support on Ubuntu 24.04

Updated on December 2, 2024
How to Install Docker with ROCm GPU Support on Ubuntu 24.04 header image

Introduction

Docker is a platform that allows you to package applications and their dependencies into isolated environments called containers, ensuring they run consistently on any system. GPU-enabled containers are specialized Docker containers that can access and use your computer's Graphics Processing Unit (GPU) for tasks requiring high computational power, such as machine learning or video processing. These containers allow applications to leverage GPU resources, which are used for compute and graphical tasks, making them ideal for performance-intensive workloads.

In this article, you are to install Docker from Docker's official repository on ROCm supported systems and access ROCm devices using a Docker container.

Install Docker

In this section, you are to add Docker's official GPG key to the system, add Docker's official repository to the system's APT sources list, and install Docker and its components such as Docker Engine, Docker CLI, Containerd, Buildx Plugin, and Docker Compose Plugin.

  1. Add Docker's official GPG key to the system.

    console
    $ sudo apt-get update
    $ sudo apt-get install ca-certificates curl
    $ sudo install -m 0755 -d /etc/apt/keyrings
    $ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    $ sudo chmod a+r /etc/apt/keyrings/docker.asc
    

    Above commands ensure that packages downloaded from Docker's repository are authentic and secure. These steps are needed before adding Docker's repository and installing the Docker engine.

  2. Add Docker's official repository to the system's APT sources list.

    console
    $ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
        $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
        sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    $ sudo apt-get update
    
  3. Install Docker and its components.

    console
    $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    

Understanding ROCm Devices

The following is the list of devices you need to expose to Docker containers.

  • /dev/kfd (Kernel Fusion Driver): It manages the communication between user applications and AMD GPUs for compute tasks. Also handles GPU memory, scheduling and execution of computational tasks like deep learning or scientific computing.
  • /dev/dri (Direct Rendering Infrastructure): It provides access to GPU for graphics rendering. Also used for 2D/3D rendering and video processing tasks, enabling graphics acceleration in applications.

Both devices are required for exposing GPU capabilities to Docker containers for GPU-accelerated tasks, such as machine learning and rendering. Learn more

Access ROCm Devices from a Container

In this section, you are to download the Docker container of a lighweight ROCm terminal and run a temporary container with ROCm GPU support.

  1. Pull lightweight ROCm terminal container image.

    console
    $ docker pull rocm/rocm-terminal:latest
    
  2. Run a temporary container.

    console
    $ docker run --rm -it --device=/dev/kfd --device=/dev/dri --security-opt seccomp=unconfined rocm/rocm-terminal
    

    The above command runs a temporary container with access to the necessary GPU devices (/dev/kfd and /dev/dri) on the system.

  3. Verify GPU availability from the container.

    console
    $ rocm-smi
    

    The above command's output should display all the devices along with their specifications.

  4. Exit and destroy the container.

    console
    $ exit
    

Conclusion

In this article, you installed Docker from its official repository on ROCm supported systems. Furthermore, you explored ROCm devices like /dev/kfd and /dev/dri and accessed ROCm devices from a container to enable GPU workloads for containerized applications.

More Resources