This error occurs when Docker cannot find the NVIDIA container runtime. It typically means the nvidia-container-toolkit is not installed, Docker's daemon.json is not configured correctly, or Docker needs to be restarted after installation.
When you try to run a Docker container with `--runtime=nvidia` or use GPU acceleration, Docker looks for the NVIDIA runtime in its configuration. This runtime acts as a bridge between Docker and your NVIDIA GPU drivers, allowing containers to access GPU resources. The "Unknown runtime specified nvidia" error indicates that Docker doesn't recognize "nvidia" as a valid runtime. This happens because: 1. The NVIDIA Container Toolkit (which includes `nvidia-container-runtime`) is not installed 2. Docker's daemon.json configuration doesn't include the nvidia runtime entry 3. Docker daemon hasn't been restarted after installing the toolkit 4. The runtime binary path is incorrect in the configuration
First, verify what runtimes Docker currently knows about:
docker info | grep -i runtimeIf you see only Runtimes: runc (without nvidia), the NVIDIA runtime is not configured. If nvidia is listed but still failing, the configuration may be incorrect.
Install the NVIDIA Container Toolkit which provides the nvidia-container-runtime:
For Ubuntu/Debian:
# Add the NVIDIA GPG key
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
# Add the repository
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
# Install the toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkitFor RHEL/CentOS:
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 yum install -y nvidia-container-toolkitUse the nvidia-ctk tool to automatically configure Docker:
sudo nvidia-ctk runtime configure --runtime=dockerThis command modifies /etc/docker/daemon.json to include the nvidia runtime. You can verify the configuration:
cat /etc/docker/daemon.jsonYou should see something like:
{
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
}
}Apply the configuration changes by restarting Docker:
sudo systemctl restart dockerAlternatively, you can send a SIGHUP signal:
sudo pkill -SIGHUP dockerdVerify the runtime is now available:
docker info | grep -i runtime
# Should show: Runtimes: nvidia runcVerify everything works by running a test container:
# Using the new --gpus flag (recommended for Docker 19.03+)
docker run --rm --gpus all nvidia/cuda:12.0-base nvidia-smi
# Or using the legacy --runtime=nvidia flag
docker run --rm --runtime=nvidia nvidia/cuda:12.0-base nvidia-smiYou should see the output of nvidia-smi showing your GPU(s).
## Using --gpus instead of --runtime=nvidia
Starting with Docker 19.03, the recommended approach is to use --gpus instead of --runtime=nvidia:
# Access all GPUs
docker run --gpus all nvidia/cuda:12.0-base nvidia-smi
# Access specific GPUs by index
docker run --gpus '"device=0,1"' nvidia/cuda:12.0-base nvidia-smi
# Access specific GPU by UUID
docker run --gpus '"device=GPU-xxxxx"' nvidia/cuda:12.0-base nvidia-smiThe --gpus flag works even without the runtimes section in daemon.json, as long as the nvidia-container-toolkit is installed.
## Docker Compose Configuration
For Docker Compose (version 2.x or later), use the deploy section:
services:
gpu-service:
image: nvidia/cuda:12.0-base
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]## WSL2 Considerations
On Windows with WSL2, the NVIDIA drivers are installed on the Windows side, but you still need the nvidia-container-toolkit inside WSL:
# In WSL2, verify NVIDIA driver is accessible
nvidia-smi
# Then install the toolkit as normal
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker## Troubleshooting Tips
- If nvidia-container-runtime is not found, verify installation: which nvidia-container-runtime
- Check for conflicting configurations in ~/.docker/daemon.json vs /etc/docker/daemon.json
- On some systems, you may need to enable the nvidia-persistenced service
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub