All articles
UncategorizedJul 06, 20260 min read— views

How to setup Ubuntu for Nvidia CUDA & Docker

This guide will walk you through the steps to set up Ubuntu for Nvidia CUDA and Docker, enabling you to leverage GPU acceleration for your applications.

A

Athicha Leksansern

Full-stack Engineer

0. Prerequisites

Reference: Ubuntu — NVIDIA Driver Installation Guide

Refresh apt and install the basic compiler tools needed by Nvidia drivers.

sudo apt update
sudo apt install -y build-essential

1. Install Nvidia CUDA/Driver

Reference: CUDA Toolkit 13.3 Update 1 Downloads | NVIDIA Developer

Add Nvidia's CUDA repository, then install the CUDA toolkit from apt.

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-13-3

Install the open Nvidia driver so CUDA can use the GPU.

sudo apt-get install -y nvidia-open

2. Install Docker

Reference: Install Docker Engine on Ubuntu | Docker Docs

Add Docker's official signing key and Ubuntu repository.

# Add Docker's official GPG key:
sudo apt update
sudo apt 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

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

Install Docker Engine and the common Docker CLI plugins.

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

Check that the Docker service is running.

sudo systemctl status docker

3. Install Nvidia Container Toolkit

Reference: Installing the NVIDIA Container Toolkit — NVIDIA Container Toolkit

Install tools needed to add Nvidia's container repository securely.

sudo apt-get update && sudo apt-get install -y --no-install-recommends \
   ca-certificates \
   curl \
   gnupg2

Add Nvidia's container toolkit repository for Docker GPU support.

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

Enable experimental packages for the selected toolkit version.

sudo sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list

Refresh apt so the new Nvidia packages are available.

sudo apt-get update

Install a pinned Nvidia Container Toolkit version for reproducibility.

export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.19.1-1
  sudo apt-get install -y \
      nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
      nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
      libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
      libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}

Configure Docker to use the Nvidia container runtime.

sudo nvidia-ctk runtime configure --runtime=docker

Restart Docker to apply the runtime change.

sudo systemctl restart docker

Optional: My setup

Reference: Terminfo - Help

Copy Ghostty's terminal definition to the server for better SSH support.

infocmp -x xterm-ghostty | ssh <YOUR-SERVER> -- tic -x -

Treat xterm-ghostty as a color-capable terminal in the shell prompt.

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color|xterm-ghostty) color_prompt=yes;;
esac

Install personal monitoring and development tools.

sudo apt install btop fastfetch nvtop lazygit

Add aliases for navigation, tmux, Git, and GPU monitoring.

alias ll='ls -la'
alias ..='cd ..'
alias ta='tmux attach-session'
alias lz='lazygit'
alias nvtop='TERM=xterm-256color nvtop'