★ Reading this for free? Get 25 structured AI courses + per-chapter AI tutor — the first chapter of every course free, no card.Start free in 30 secondsOr own it all: Lifetime $149, pay once

Docker Can't See Your GPU: Fix "could not select device driver" in Five Steps

The error could not select device driver "" with capabilities: [[gpu]] means Docker has no NVIDIA runtime registered. On a Linux host, two commands fix it: sudo nvidia-ctk runtime configure --runtime=docker followed by sudo systemctl restart docker — assuming nvidia-container-toolkit is already installed. If you are on Docker Desktop with WSL2, on a Mac, on rootless Docker, or on AMD, none of that applies and you need a different section of this page.

📅 Published: September 20, 2026🔄 Last Updated: September 20, 2026✓ Manually Reviewed

Nearly every top result for this error string is a Stack Overflow answer from the nvidia-docker2 era. Those answers still work often enough to be believable and wrong often enough to waste your evening — and none of them cover the two cases that actually bite local-AI users: Docker Desktop on Windows, and the container that runs on the GPU for ten minutes and then quietly drops to CPU. Everything below was checked against NVIDIA's, Docker's and Ollama's current documentation on August 18, 2026.

Which fix applies to you?

Two questions. The answer is the exact command block for your setup — every one of them is copied from the vendor documentation cited underneath it, not from memory.

Install the toolkit, then register it with Docker. The second command is the one everyone forgets.

Installing nvidia-container-toolkit does not tell the Docker daemon about it. Until nvidia-ctk rewrites /etc/docker/daemon.json and the daemon restarts, --gpus all keeps returning the device-driver error.

# 1. Add NVIDIA's production repo (Ubuntu/Debian)
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
sudo apt-get update

# 2. Install
sudo apt-get install -y nvidia-container-toolkit

# 3. Register the runtime with Docker  <-- the step that fixes the error
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

# 4. Canary
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi

Commands taken from NVIDIA's current installation guide and Ollama's Docker doc, checked August 18, 2026.

Step 1: Prove the host can see the GPU

Run nvidia-smi on the host, outside any container. If that fails, stop — this is a driver problem and no Docker configuration will fix it.

This takes four seconds and eliminates a whole class of wasted effort. The most common way people land here without realising it: a kernel or driver package upgraded through apt and the machine was never rebooted, so the running kernel module and the userspace driver no longer match. A reboot is the fix, and it is embarrassing how often that is the whole answer.

nvidia-smi          # must print your GPU and a driver version
uname -r            # running kernel

Step 2: Install the NVIDIA Container Toolkit (not nvidia-docker2)

The package you want is nvidia-container-toolkit. NVIDIA's current install guide pins version 1.20.0-1.

The repository setup below is copied verbatim from NVIDIA's installation guide, which is also the exact sequence Ollama's Docker documentation links to. If you want the reproducible build, pin the version; if you want whatever is current, drop the pin and install the bare package name.

# Ubuntu / Debian
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
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit

# Fedora / RHEL / Amazon Linux
curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo \
  | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
sudo dnf install -y nvidia-container-toolkit

# openSUSE / SLE
sudo zypper ar https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo
sudo zypper --gpg-auto-import-keys install -y nvidia-container-toolkit

Source: NVIDIA Container Toolkit installation guide, section "Installation", as published on August 18, 2026.

Step 3: Register the runtime with Docker — the step everyone skips

Installing the package does not tell Docker about it. Until nvidia-ctk rewrites /etc/docker/daemon.json and the daemon restarts, --gpus all keeps failing with the same error.

sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

If you are running rootless Docker, this command writes to the wrong file. NVIDIA documents a separate three-command path: point nvidia-ctk at $HOME/.config/docker/daemon.json, restart with systemctl --user restart docker, then set nvidia-container-cli.no-cgroups in the toolkit config. Pick "rootless" in the picker above for the exact block.

Step 4: Run the canary before you touch your real stack

sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi is NVIDIA's own sample workload. If it prints your GPU table, Docker is fixed and any remaining problem belongs to your application container.

Note the image: plain ubuntu. You do not need a CUDA image to test this, because the toolkit injects the driver libraries into whatever container you run. That matters, because half the guides on the internet hand you a nvidia/cuda: tag that was deleted years ago, and you end up debugging a manifest-not-found error instead of your actual problem. If you do want a CUDA base image, pull the tag from the current nvidia/cuda tag listing rather than copying one out of a tutorial — the tag set is pruned regularly, and a tag that worked when an article was written is the single most common reason these commands fail for a reason unrelated to your GPU.

# NVIDIA's documented sample workload
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi

# Ollama's variant, if you prefer
docker run --gpus all ubuntu nvidia-smi

Sources: NVIDIA Container Toolkit "Running a Sample Workload"; Ollama troubleshooting docs, "Linux NVIDIA Troubleshooting".

Step 5: Translate it to Compose

Compose does not understand --gpus. You declare a device reservation, and the capabilities field is mandatory — omit it and the service errors on deployment.

services:
  ollama:
    image: ollama/ollama
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
volumes:
  ollama:

count takes an integer or all. device_ids takes host GPU IDs as printed by nvidia-smi. Docker's docs state the two are mutually exclusive — set one, never both, or the service fails to start. Once this works, our Ollama + Open WebUI Compose walkthrough is the happy path from here.

The error strings, decoded

Five different messages, four different root causes. Match the exact text you pasted into Google against the left column. Every fix in the right column is from vendor documentation, cited below the table.

What you seeWhat it meansFix
could not select device driver "" with capabilities: [[gpu]]Docker parsed --gpus, then found no device driver registered that can satisfy a "gpu" capability. The NVIDIA container runtime is either not installed or not wired into the daemon.Install nvidia-container-toolkit, then run nvidia-ctk runtime configure --runtime=docker and restart Docker.
unknown or invalid runtime name: nvidiaYou passed --runtime=nvidia but /etc/docker/daemon.json has no "nvidia" runtime entry. Same root cause, different phrasing.nvidia-ctk runtime configure --runtime=docker writes that entry for you. Restart the daemon afterwards.
docker: Error response from daemon: failed to create task ... nvidia-container-cli: initialization errorThe runtime is registered but libnvidia-container cannot talk to the driver — usually a host driver that is missing, mismatched, or was upgraded without a reboot.Run nvidia-smi on the host first. If that fails, this is a driver problem and no amount of Docker configuration will help.
GPU discovery failures in the server log after it had been workingDocumented by Ollama: systemd cgroup management in Docker can detach the GPU from a long-running container.Add "exec-opts": ["native.cgroupdriver=cgroupfs"] to /etc/docker/daemon.json on the host and restart Docker.
AMD: permissions error opening /dev/kfd in the server logThe container process is not a member of the host groups that own /dev/kfd and /dev/dri.Read the numeric GIDs with ls -lnd /dev/kfd /dev/dri /dev/dri/* and pass matching --group-add flags.

Sources: NVIDIA Container Toolkit installation guide and release notes (v1.20.0); Docker Docs, "Enable GPU access with Docker Compose"; Ollama troubleshooting documentation. Checked August 18, 2026. We have ordered these by how often they turn out to be the answer in support threads we read, not by any measured distribution — treat the ordering as a heuristic, not a statistic.

The Docker Desktop and WSL2 case (the most confused one)

On Docker Desktop you do not install the NVIDIA Container Toolkit inside your WSL distro. The GPU comes through WSL2 GPU paravirtualization, and everything you configure lives on the Windows side.

Docker's documentation lists four prerequisites: a Windows machine with an NVIDIA GPU, an up-to-date Windows 10 or 11 install, an up-to-date Windows NVIDIA driver that supports WSL2 GPU paravirtualization, and the latest WSL2 Linux kernel (wsl --update) — with the WSL2 backend turned on in Docker Desktop settings. Nothing in that list is a package inside Ubuntu-on-WSL.

The trap: people follow a Linux tutorial, apt-get install an NVIDIA driver inside the distro, and break the paravirtualized one that was already working. If you have done that, remove the Linux-side driver packages before anything else.

The part nobody tells Mac and Linux desktop users: Docker's docs say plainly that GPU support in Docker Desktop is only available on Windows with the WSL2 backend. If you are running Docker Desktop on macOS or on a Linux desktop, there is no flag that will expose the GPU. Run the tool natively instead — our Mac local AI setup guide takes the native route.

It worked, then it silently dropped to CPU

Add "exec-opts": ["native.cgroupdriver=cgroupfs"] to /etc/docker/daemon.json on the host and restart Docker.

This one deserves its own section because it does not look like a GPU problem. Nothing errors. The container keeps answering. Tokens just get slow, and the only visible clue is GPU-discovery failures in the container log. Ollama's troubleshooting page documents the cause — systemd cgroup management in Docker detaching the GPU from a long-running container — and this fix appears in essentially no general CUDA-in-Docker guide.

sudo nano /etc/docker/daemon.json
# merge this key with whatever is already in the file
#   "exec-opts": ["native.cgroupdriver=cgroupfs"]

sudo systemctl restart docker
docker logs -f ollama   # watch for GPU discovery lines on the next request

Before you blame the runtime, rule out the boring explanation: a model that no longer fits. Ollama offloads layers to CPU when VRAM runs short, and the symptom is identical. Check the numbers in our VRAM calculator, and see the Ollama troubleshooting guide for the non-Docker version of this diagnosis.

AMD and ROCm: forget --gpus entirely

ROCm containers take --device /dev/kfd --device /dev/dri and, on many distros, explicit --group-add flags with numeric group IDs read from the host.

If you typed --gpus all on an AMD box you will chase the device-driver error forever, because that flag is the NVIDIA path. Ollama's documented AMD invocation maps the two device nodes and uses the :rocm image tag. Access to /dev/kfd normally needs video and/or render group membership; inside a container you have to add those groups by their numeric ID, because the names do not map across the boundary.

# read the NUMERIC gids (note the -n)
ls -lnd /dev/kfd /dev/dri /dev/dri/*
# crw-rw---- 1 0  44 226, 0 Sep 16 16:55 /dev/dri/card0   <- 44 is the group id

docker run -d --device /dev/kfd --device /dev/dri \
  --group-add 44 \
  -v ollama:/root/.ollama -p 11434:11434 \
  --name ollama ollama/ollama:rocm

One AMD-specific trap worth knowing before you blame Docker: Ollama ships ROCm 7 libraries and needs a matching ROCm 7 kernel driver. On an older host driver, GPU discovery hangs for about 30 seconds, times out, and falls back to CPU — a failure that looks like a container permissions problem but is not. Ollama's docs point at amdgpu-install for the upgrade. Our AMD ROCm setup guide covers getting the host side right first, which is the order that saves time.

What this page does not claim

Three honest limits, so you know where to stop trusting us.

  • We have not reproduced every branch on every distro. The commands here are transcribed from current vendor documentation and checked for existence — the CUDA image tag, the toolkit version, the Compose schema. Where a fix depends on hardware we do not have in front of us (a specific AMD card, a specific Windows driver), we tell you what to check rather than what result to expect.
  • The ordering is a heuristic. We put "runtime not registered" first because it is the most common cause in the support threads we read, not because any distribution was ever counted.
  • Snap-packaged Docker is its own world. On Ubuntu, a Docker installed from Snap has confinement rules that can block device access even after the toolkit is configured correctly. If snap list docker returns a row, that is worth eliminating before you keep editing daemon.json — reinstalling from Docker's own apt repository puts you back on the documented path.

Once the GPU is visible

If the canary prints your GPU table and your app still runs on CPU, the problem has moved into the application container.

ComfyUI, vLLM and Ollama each have their own device-selection logic that runs after Docker hands the GPU over — a wrong base image, a CPU-only PyTorch wheel, or a model that simply does not fit. Start with the ComfyUI guide for the image stack, Ollama setup mistakes for the configuration ones, and Docker Model Runner if you would rather let Docker manage models instead of maintaining your own Compose file.

Frequently Asked Questions

What does "could not select device driver '' with capabilities: [[gpu]]" actually mean?

It means the Docker daemon accepted your --gpus flag but has no registered device driver able to provide a GPU. It is not a CUDA error, a driver error, or a model error — it happens before your container starts. On a Linux host the cause is almost always that nvidia-container-toolkit is either not installed or was installed without running "sudo nvidia-ctk runtime configure --runtime=docker" and restarting the daemon. Install plus configure plus restart, in that order, resolves the plain version of this error.

Do I still need to install nvidia-docker2?

No. NVIDIA's current installation guide has you install the nvidia-container-toolkit package (pinned at 1.20.0-1 in the docs as of August 18, 2026) and configure the runtime with nvidia-ctk. nvidia-docker2 was the older wrapper package, and the top Stack Overflow answers for this error string still tell you to install it. If you follow those answers on a current distro you will spend an evening fighting package resolution for a step you no longer need.

Why does my container use the GPU at first and then switch to CPU?

This is a distinct failure mode with its own documented fix, and it is not covered by generic CUDA-in-Docker guides. Ollama's troubleshooting page describes it exactly: the container starts on the GPU, then the server log reports GPU discovery failures and generation slows to CPU speed. The fix is to disable systemd cgroup management on the host — add "exec-opts": ["native.cgroupdriver=cgroupfs"] to /etc/docker/daemon.json and restart Docker. This applies to Linux hosts, not Docker Desktop.

Can Docker Desktop on a Mac use the GPU?

No. Docker's documentation states that GPU support in Docker Desktop is only available on Windows with the WSL2 backend. A container on an Apple Silicon Mac gets CPU only — there is no Metal passthrough, and no flag will create one. Run Ollama, whisper.cpp or ComfyUI natively on macOS instead; the native builds reach the Apple GPU, the containerised ones cannot.

How do I do this in Docker Compose instead of docker run?

Compose ignores --gpus. You declare a device reservation under deploy.resources.reservations.devices with driver: nvidia and capabilities: [gpu]. Docker's docs are explicit that capabilities is mandatory — leave it out and the service errors on deployment. count and device_ids are mutually exclusive, so set one or the other, never both. For AMD there is no reservation shim at all: you map /dev/kfd and /dev/dri as devices and add the host group IDs with group_add.

Sources

Every command on this page is transcribed from the vendor documentation linked above. Nothing here is presented as a measurement of our own hardware.

Embed this free Docker GPU Fix Picker on your site

Free to use — just keep the attribution link. Works on any site.

<iframe src="https://localaimaster.com/embed/docker-gpu-not-detected" width="100%" height="560" style="border:1px solid var(--line);border-radius:12px;max-width:680px" title="Docker GPU Fix Picker — Local AI Master" loading="lazy"></iframe>
<p style="font:13px/1.5 system-ui,sans-serif;max-width:680px;margin:6px 0 0"><a href="https://localaimaster.com/tools/docker-gpu-not-detected">Docker GPU Fix Picker</a> by <a href="https://localaimaster.com">Local AI Master</a></p>
Once your hardware is sorted

Know what to actually run on it

All 561 chapters — running local models, RAG, agents, fine-tuning — plus the Python Lab and every course added later.

$149 once unlocks everything, forever — about $0.27/chapter for life. Prefer to spread it out? Pro is $79/year (saves 27%) or $8.99/month.
Secure checkout by Lemon Squeezy — your card never touches this siteInstant access the moment you payFirst chapter of every course is free — try before you buy

Ready to Go Beyond Tutorials?

25 structured courses with hands-on chapters - build RAG chatbots, AI agents, and ML pipelines on your own hardware.

Bonus kit

Ollama Docker Templates

10 one-command Docker stacks with the GPU reservation already written for you. Included with paid plans, or free after subscribing to both Local AI Master and Little AI Master on YouTube.

See Plans →

Was this helpful?

LM

Written by the Local AI Master Team

The team behind Local AI Master

We build Local AI Master around practical, testable local AI workflows: model selection, hardware planning, RAG systems, agents, and MLOps. The goal is to turn scattered tutorials into a structured learning path you can follow on your own hardware.

✓ Local AI Curriculum✓ Hands-On Projects✓ Open Source Contributor
📚
Free · no account required

Grab the AI Starter Kit — career roadmap, cheat sheet, setup guide

No spam. Unsubscribe with one click.

Free Tools & Calculators