DEV Community

Cover image for Installing Docker with ROCm GPU Support on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Installing Docker with ROCm GPU Support on Ubuntu 24.04

Docker is a platform that packages applications and their dependencies into isolated containers so they run consistently on any system. GPU-enabled containers extend this by giving containerized applications access to a machine's Graphics Processing Unit (GPU) for compute-heavy workloads such as machine learning or video processing. This guide installs Docker from Docker's official repository on a ROCm-supported Ubuntu 24.04 system and accesses ROCm devices from inside a Docker container, assuming a GPU-enabled server with an AMD ROCm-capable GPU already set up. By the end, you'll have Docker installed and a temporary container running with verified access to the host's ROCm GPU devices.


Install Docker

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

$ 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
Enter fullscreen mode Exit fullscreen mode

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

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

$ 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
Enter fullscreen mode Exit fullscreen mode

3. Install Docker and its components:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode

This installs Docker Engine, the Docker CLI, Containerd, the Buildx plugin, and the Docker Compose plugin.

Understand the ROCm Devices Exposed to Containers

Two host devices need to be exposed to Docker containers for GPU-accelerated workloads:

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

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

1. Pull a lightweight ROCm terminal container image:

$ docker pull rocm/rocm-terminal:latest
Enter fullscreen mode Exit fullscreen mode

2. Run a temporary container with access to the GPU devices:

$ docker run --rm -it --device=/dev/kfd --device=/dev/dri --security-opt seccomp=unconfined rocm/rocm-terminal 
Enter fullscreen mode Exit fullscreen mode

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

3. Verify GPU availability from inside the container:

$ rocm-smi
Enter fullscreen mode Exit fullscreen mode

The output should display all the detected GPU devices along with their specifications.

4. Exit and destroy the container:

$ exit
Enter fullscreen mode Exit fullscreen mode

Next Steps

  • Install a machine learning framework such as PyTorch or TensorFlow with ROCm acceleration inside a container.
  • Build a custom Dockerfile that layers your application on top of a ROCm base image.
  • Orchestrate multiple ROCm-enabled containers with a container orchestrator such as Kubernetes.
  • Monitor GPU utilization with rocm-smi while running production workloads.

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)