[Solved] nvidia-docker runtime Error: (Unknown runtime specified nvidia)

1. An error is reported when running the docker command

[email protected]:~# docker run --runtime=nvidia -ti  -v $(pwd):/workspace -w /workspace -v /nfs:/nfs [email protected] --privileged -v /var/run/docker.sock:/var/run/docker.sock registry.test.cn/mla/cxx_toolchains:latest
docker: Error response from daemon: Unknown runtime specified nvidia.
See 'docker run --help'.

According to the error prompt, check whether NVIDIA-docker is installed

[email protected]:~# nvidia-docker
nvidia-docker: command not found
[email protected]:~# 

Obviously, it is not installed

2 execute the script and install NVIDIA-docker

[email protected]:~# cat install-nvidia-docker.sh
sudo curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
sudo curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
[email protected]:~#

Check that NVIDIA-docker and NVIDIA-container-Runtim are installed successfully

[email protected]:~# which nvidia-docker
/usr/bin/nvidia-docker
[email protected]:~# which nvidia-container-runtime
/usr/bin/nvidia-container-runtime
[email protected]:~#

3 edit /etc/docker/daemon.JSON is as follows

[email protected]:~# cat /etc/docker/daemon.json
{
  "insecure-registries": ["registry.test.cn"],
  "max-concurrent-downloads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "live-restore": true,
  "metrics-addr": "0.0.0.0:9323",
  "default-runtime": "nvidia",
  "experimental": true,
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}
[email protected]:~#

4 restart docker

[email protected]:~# systemctl daemon-reload
[email protected]:~# systemctl restart docker

5 verification

[email protected]:~# docker run --runtime=nvidia -ti  -v $(pwd):/workspace -w /workspace -v /nfs:/nfs [email protected] --privileged -v /var/run/docker.sock:/var/run/docker.sock registry.test.cn/mla/cxx_toolchains:latest
[email protected]:/workspace#
[email protected]:/workspace# ls
[email protected]:/workspace# pwd
/workspace
[email protected]:/workspace#

Read More: