After installing Docker on a GPU Cloud Server, you might encounter the docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]] error when you start a container from an image by running the docker run --gpus all [image-name] command. This error occurs because the NVIDIA Container Toolkit is not installed.
Symptoms
On a GPU Cloud Server with Docker installed, when you run the docker run --gpus all [image-name] command to start a Docker container, the following error message appears:
ecs-user@xxx:~$ sudo docker run --gpus all ac2-registry.cn-hangzhou.cr.aliyuncs.com/ac2/base:alinux3.2104
Unable to find image 'ac2-registry.cn-hangzhou.cr.aliyuncs.com/ac2/base:alinux3.2104' locally
a1xxx04: Pulling from ac2/base
49xxx e3: Pull complete
30xxx 7c: Pull complete
17xxx ee: Pull complete
75xxx 8a: Pull complete
9fxxx 55: Pull complete
edxxx 55: Pull complete
Digest: sha256:5065d5946b1e30xxx7xxx4fxxx8xxxdxxx74acxxx6d0180f97
Status: Downloaded newer image for ac2-registry.cn-hangzhou.cr.aliyuncs.com/ac2/base:alinux3.2104
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]
Cause
The NVIDIA Container Toolkit allows Docker to access GPU resources. Without this toolkit, Docker cannot select a GPU device, which triggers the error.
Solution
-
Run the following command to verify that the NVIDIA GPU driver is installed on the GPU instance.
NoteGPU instances do not come with pre-installed drivers. You must install a driver manually, as Docker cannot access the GPU device without one.
nvidia-smiIf the output displays the driver version, as shown in the following example, the NVIDIA GPU driver is installed. If not, see Install a Tesla driver or Install a GRID driver to install the required driver.
NVIDIA-SMI 550.127.08 Driver Version: 550.127.08 CUDA Version: 12.4 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 A10 On | 00000000:00:07.0 Off | 0 0% 27C P8 10W / 150W | 1MiB / 23028MiB | 0% Default | | | N/A | Processes: GPU GI CI PID Type Process name GPU Memory ID ID Usage No running processes found -
Run the following command to verify that Docker is installed on the GPU instance.
sudo docker -vIf the output displays the Docker version, as shown in the following example, Docker is installed. If not, see Install and use Docker and Docker Compose to install Docker.
[ecs-xxx ~]$ sudo docker -v Docker version 26.1.3, build b72abbb -
Run the following commands to install the NVIDIA Container Toolkit.
The following commands are examples for CentOS, Alibaba Cloud Linux, and Ubuntu. For installation commands on other operating systems, see Installing the NVIDIA Container Toolkit.
-
For Alibaba Cloud Linux 3 and CentOS 8
# Configure the repository. 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 # Install the toolkit. sudo yum install -y nvidia-container-toolkit # Restart the Docker service. sudo systemctl restart docker -
For Ubuntu
# Configure the repository. 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 # Install the toolkit. sudo apt-get install -y nvidia-container-toolkit # Restart the Docker service. sudo systemctl restart docker
-
-
To verify the installation, run the command for your operating system:
-
For CentOS and Alibaba Cloud Linux
sudo rpm -qa | grep nvidia-container-toolkit -
For Ubuntu
sudo dpkg -l | grep nvidia-container-toolkit
If the output displays the NVIDIA Container Toolkit version, as shown in the following example, the toolkit is installed.
ecs-uxxxx@xxxxxxxxxxxxxxxxxxxxx:~$ sudo dpkg -l | grep nvidia-container-toolkit ii nvidia-container-toolkit 1.17.5-1 amd64 NVIDIA Container toolkit ii nvidia-container-toolkit-base 1.17.5-1 amd64 NVIDIA Container Toolkit Base -
-
Run
docker run --gpus all [image-name]again to verify that the issue is resolved.