<pre><code>sudo apt update
sudo apt install -y gcc make
wget https://us.download.nvidia.com/tesla/550.90.07/NVIDIA-Linux-x86_64-550.90.07.run
chmod +x NVIDIA-Linux-x86_64-550.90.07.run
sudo ./NVIDIA-Linux-x86_64-550.90.07.run
</code></pre>
<p>Install these and try again.</p>
<p>my docker-compose file</p>
<pre><code>test:
    build:
      context: ../test
      dockerfile: Dockerfile
    ports:
      - &quot;8099:8099&quot;
    restart: always
    container_name: test
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1  # Specifies the number of GPUs to reserve
              capabilities: [gpu]
</code></pre>

CC BY-SA 4.0
2024-08-13T16:11:11.703Z
2024-08-13T16:11:11.703Z
playwithcode
<p>I've been trying to run the <a href="https://github.com/pytorch/pytorch/tree/main/.devcontainer" rel="nofollow noreferrer">official PyTorch Devcontainer</a> for <em>VSCode</em>, but whenever I attempt to open my project in a container, it fails and the logs reveal the following message (<em>container ID redacted cause idk if this is a privacy concern or something</em>):</p>
<pre><code>...
[2024-08-08T09:00:45.137Z] Start: Starting container
[2024-08-08T09:00:45.137Z] Start: Run: docker start [CONTAINER ID]
[2024-08-08T09:00:45.228Z] Error response from daemon: could not select device driver &quot;&quot; with capabilities: [[gpu]]

[2024-08-08T09:00:45.230Z] Error: failed to start containers: [CONTAINER ID]

[2024-08-08T09:00:45.232Z] Stop (95 ms): Run: docker start [CONTAINER ID]
....
</code></pre>
<p>This has been tried on both the cloned full PyTorch repo, and by copy and pasting the <code>.devcontainer</code> folder into a separate project.</p>
<p><strong>The issue is</strong> that not only have I <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html" rel="nofollow noreferrer">installed the NVIDIA Container Toolkit</a> <strong>and</strong> configured it for docker, but Docker also happily runs my GPU through to a container when testing it in the terminal! The following command is <em>literally</em> on <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/sample-workload.html#running-a-sample-workload-with-docker" rel="nofollow noreferrer">NVIDIA's official install guide</a>:</p>
<pre><code>$ sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
Thu Aug  8 09:04:19 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 555.58.02              Driver Version: 555.58.02      CUDA Version: 12.5     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 2070        Off |   00000000:08:00.0  On |                  N/A |
|  0%   35C    P8             13W /  225W |     653MiB /   8192MiB |      6%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
</code></pre>
<p>Every piece of advice that I have followed online tells me to configure settings for docker, but all of them end with using this above command to verify that docker can indeed read my GPU. A common check is to see whether the daemon is using the correct runtime. but lo and behold:</p>
<pre><code>$ sudo cat /etc/docker/daemon.json 
{
    &quot;default-runtime&quot;: &quot;nvidia&quot;,
    &quot;runtimes&quot;: {
        &quot;nvidia&quot;: {
            &quot;args&quot;: [],
            &quot;path&quot;: &quot;nvidia-container-runtime&quot;
        }
    }
}
</code></pre>
<p>Other devcontainers (such as a Haskell one and a LaTeX one) run perfectly fine on my system, and Docker Desktop recognises the container was &quot;Created (128)&quot;. The <code>.devcontainer</code> folder I'm using for this is found <a href="https://github.com/pytorch/pytorch/tree/main/.devcontainer" rel="nofollow noreferrer">on the official PyTorch GitHub Repository</a>; I'm using the <code>CUDA</code> option when prompted by VSCode.</p>
<p>I'd really really appreciate any help towards fixing this issue and allowing me to run PyTorch in a devcontainer. I can happily provide the outputs of other files to diagnose the problem.</p>

<docker><vscode>
Devcontainer won't recognise my GPU despite docker itself recognising it perfectly fine
Cem
# Devcontainer won't recognise my GPU despite docker itself recognising it perfectly fine

(Asked by: username_0 on 2024-08-08)

I've been trying to run the official PyTorch Devcontainer for VSCode, but whenever I attempt to open my project in a container, it fails and the logs reveal the following message (container ID redacted cause idk if this is a privacy concern or something):
...
[2024-08-08T09:00:45.137Z] Start: Starting container
[2024-08-08T09:00:45.137Z] Start: Run: docker start [CONTAINER ID]
[2024-08-08T09:00:45.228Z] Error response from daemon: could not select device driver "" with capabilities: [[gpu]]

[2024-08-08T09:00:45.230Z] Error: failed to start containers: [CONTAINER ID]

[2024-08-08T09:00:45.232Z] Stop (95 ms): Run: docker start [CONTAINER ID]
....

This has been tried on both the cloned full PyTorch repo, and by copy and pasting the .devcontainer folder into a separate project.
The issue is that not only have I installed the NVIDIA Container Toolkit and configured it for docker, but Docker also happily runs my GPU through to a container when testing it in the terminal! The following command is literally on NVIDIA's official install guide:
$ sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
Thu Aug  8 09:04:19 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 555.58.02              Driver Version: 555.58.02      CUDA Version: 12.5     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 2070        Off |   00000000:08:00.0  On |                  N/A |
|  0%   35C    P8             13W /  225W |     653MiB /   8192MiB |      6%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+

Every piece of advice that I have followed online tells me to configure settings for docker, but all of them end with using this above command to verify that docker can indeed read my GPU. A common check is to see whether the daemon is using the correct runtime. but lo and behold:
$ sudo cat /etc/docker/daemon.json 
{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}

Other devcontainers (such as a Haskell one and a LaTeX one) run perfectly fine on my system, and Docker Desktop recognises the container was "Created (128)". The .devcontainer folder I'm using for this is found on the official PyTorch GitHub Repository; I'm using the CUDA option when prompted by VSCode.
I'd really really appreciate any help towards fixing this issue and allowing me to run PyTorch in a devcontainer. I can happily provide the outputs of other files to diagnose the problem.

**Tags:** docker, vscode


---

## 1 answers

### Answer by username_1 on 2024-08-13. Score: 0

sudo apt update
sudo apt install -y gcc make
wget https://us.download.nvidia.com/tesla/550.90.07/NVIDIA-Linux-x86_64-550.90.07.run
chmod +x NVIDIA-Linux-x86_64-550.90.07.run
sudo ./NVIDIA-Linux-x86_64-550.90.07.run

Install these and try again.
my docker-compose file
test:
    build:
      context: ../test
      dockerfile: Dockerfile
    ports:
      - "8099:8099"
    restart: always
    container_name: test
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1  # Specifies the number of GPUs to reserve
              capabilities: [gpu]


---

