<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Takeo</title>
    <description>The latest articles on DEV Community by Takeo (@takeofuture).</description>
    <link>https://dev.to/takeofuture</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4049905%2Fd2644aef-bfe1-4d63-b446-ed732da60feb.png</url>
      <title>DEV Community: Takeo</title>
      <link>https://dev.to/takeofuture</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/takeofuture"/>
    <language>en</language>
    <item>
      <title>How to Use an NVIDIA GPU Inside a Docker Container</title>
      <dc:creator>Takeo</dc:creator>
      <pubDate>Mon, 27 Jul 2026 18:00:38 +0000</pubDate>
      <link>https://dev.to/takeofuture/how-to-use-an-nvidia-gpu-inside-a-docker-container-4l36</link>
      <guid>https://dev.to/takeofuture/how-to-use-an-nvidia-gpu-inside-a-docker-container-4l36</guid>
      <description>&lt;p&gt;I do not normally use Docker very often. However, I recently needed to install PyTorch3D, a library that is no longer actively updated, and I could not get it working properly in my current environment.&lt;/p&gt;

&lt;p&gt;I could have launched a separate GPU machine running the older Ubuntu 22.04 or installed another CUDA version on the host system. However, I was concerned that adding multiple CUDA versions might cause problems with library paths and symbolic links.&lt;/p&gt;

&lt;p&gt;So, somewhat reluctantly, I decided to use Docker.&lt;/p&gt;

&lt;p&gt;Running a normal Docker container is relatively straightforward: pull an image and start the container. However, when using a GPU machine, some additional configuration is required to make the host GPU available inside the container.&lt;/p&gt;

&lt;p&gt;This article is a short memo describing the setup process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Host environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My host environment is Ubuntu 24.04 with CUDA 13.1.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Futi3tktjql3bvle9pdbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Futi3tktjql3bvle9pdbm.png" alt=" " width="394" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following command also displays information about the NVIDIA driver and the GPU:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# nvidia-smi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6et5cmjjml23yh57psph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6et5cmjjml23yh57psph.png" alt=" " width="659" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although nvidia-smi may display a different CUDA version, the CUDA Toolkit installed on the host is CUDA 13.1, as shown by the output of nvcc --version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Target Docker environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For this test, I wanted to launch a container with the following combination:&lt;/p&gt;

&lt;p&gt;Ubuntu 22.04&lt;br&gt;
CUDA 12.4.1&lt;/p&gt;

&lt;p&gt;To make the host GPU available inside Docker containers, the NVIDIA Container Toolkit must first be installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing the NVIDIA Container Toolkit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I installed it using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 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' | \
  tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

# apt update
# apt install nvidia-container-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The installation completed without any problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configuring Docker to use the NVIDIA runtime&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, configure Docker to use the NVIDIA Container Runtime and restart the Docker service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# nvidia-ctk runtime configure --runtime=docker
# systemctl restart docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can confirm that the NVIDIA runtime has been registered by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# docker info | grep -i runtime
 Runtimes: nvidia runc io.containerd.runc.v2
 Default Runtime: runc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also inspect Docker's configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cat /etc/docker/daemon.json
{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default runtime remains runc, but the NVIDIA runtime is now available when a container is started with GPU support.&lt;/p&gt;

&lt;p&gt;Selecting a CUDA Docker image&lt;/p&gt;

&lt;p&gt;For this example, I used a CUDA 12.4.1 runtime image based on Ubuntu 22.04.&lt;/p&gt;

&lt;p&gt;Other CUDA and Ubuntu combinations can be found on the NVIDIA CUDA image page on Docker Hub:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Selecting a CUDA Docker image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For this example, I used a CUDA 12.4.1 runtime image based on Ubuntu 22.04.&lt;/p&gt;

&lt;p&gt;Other CUDA and Ubuntu combinations can be found on the NVIDIA CUDA image page on Docker Hub:&lt;br&gt;
&lt;a href="https://hub.docker.com/r/nvidia/cuda/tags" rel="noopener noreferrer"&gt;CUDA Image&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing GPU access inside the container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To confirm that the GPU is available inside the Docker container, run nvidia-smi in the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# docker run --rm --gpus all \
  nvidia/cuda:12.4.1-runtime-ubuntu22.04 \
  nvidia-smi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The options used here are:&lt;/p&gt;

&lt;p&gt;--rm: Automatically removes the container after it exits.&lt;br&gt;
--gpus all: Makes all available host GPUs accessible inside the container.&lt;br&gt;
nvidia/cuda:12.4.1-runtime-ubuntu22.04: Specifies the CUDA 12.4.1 runtime image based on Ubuntu 22.04.&lt;br&gt;
nvidia-smi: Runs the NVIDIA system management command inside the container.&lt;/p&gt;

&lt;p&gt;If the setup is working correctly, information about the host GPU should be displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fteg7jt3nqutad1k1e3hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fteg7jt3nqutad1k1e3hp.png" alt=" " width="800" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The downloaded Docker image can also be confirmed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# docker image ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcd08mnsg3vjnjae4lwbi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcd08mnsg3vjnjae4lwbi.png" alt=" " width="720" height="40"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By installing the NVIDIA Container Toolkit and starting the container with the --gpus all option, I was able to use the host GPU from a Docker container running an older combination of Ubuntu and CUDA.&lt;/p&gt;

&lt;p&gt;This approach is useful when a library requires an older CUDA or operating-system environment and you do not want to modify the CUDA configuration of the host machine.&lt;/p&gt;

&lt;p&gt;In my case, Docker allowed me to prepare an Ubuntu 22.04 and CUDA 12.4.1 environment without adding another CUDA installation directly to my Ubuntu 24.04 host.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
