Nvidia/cuda doesn't work on Docker Desktop but works on Docker Engine

Hi. I’m trying to comb through the forum, documentation and google search but none of the things I’ve read solved my problem so far.

“docker run --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi” on Docker Desktop gives the following error:

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as ‘legacy’

nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown.

But, using docker engine only, the container works just fine.

OS Version/Build

Docker Desktop 4.13.0 (89412) → installed through DEB package.
OS: Ubuntu 22.04.1 LTS 64-bit
Nvidia driver: 520.56.06
Package: nvidia-container-toolkit
Version: 1.12.0~rc.1-1
Priority: optional
Section: utils
Maintainer: NVIDIA CORPORATION <cudatools@nvidia.com>
Installed-Size: 2,172 kB
Depends: nvidia-container-toolkit-base (= 1.12.0~rc.1-1), libnvidia-container-tools (>= 1.12.0~rc.1-1), libnvidia-container-tools (<< 2.0.0), libseccomp2
Breaks: nvidia-container-runtime (<= 3.5.0-1), nvidia-container-runtime-hook
Replaces: nvidia-container-runtime (<= 3.5.0-1), nvidia-container-runtime-hook

Docker Desktop Version

Docker Desktop 4.13.0 (89412)
Context: desktop-linux
Debug Mode: false
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
compose: Docker Compose (Docker Inc., v2.12.0)
dev: Docker Dev Environments (Docker Inc., v0.0.3)
extension: Manages Docker extensions (Docker Inc., v0.2.13)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.21.0)

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 20.10.20
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc version: v1.1.4-0-g5fd4c4d
init version: de40ad0
Security Options:
Profile: default
Kernel Version: 5.15.49-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 6
Total Memory: 7.589GiB
Name: docker-desktop
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
Live Restore Enabled: false

Steps to reproduce

  1. clean install of Ubuntu 22.04.1 LTS
  2. update, upgrade, install curl, nvidia-driver-520, qemu, uidmap, ca-certificates, gnupg, lsb-release
  3. add user to kvm group
  4. restart PC
  5. create folder /etc/apt/keyrings
  6. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  7. create /etc/apt/sources.list.d/docker.list and put in "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable"
  8. apt update and install docker-desktop-4.13.0-amd64.deb (sudo apt-get install docker-desktop-4.13.0-amd64.deb)
  9. add user to docker (usermod -aG docker $USER), then “newgrp docker”
  10. Install Nvidia container toolkit
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/experimental/ubuntu22.04/libnvidia-container.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
  1. Actvivate Docker Desktop found in Ubuntu applications.
  2. On the terminal
docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi

When using docker engine (install via https://get.docker.com) it works without any hitch. I’ll get by using docker engine for now, but I’d like to be able to use docker desktop in the future. Hope someone can help me fix this problem. Is Docker Desktop for Linux still in beta?

Sorry for the lengthy post. Thank you for reading!

1 Like

I’m running into the same issue. It appears to be a permissions problem. Running docker as sudo works if you’re pulling an image from elsewhere, however sudo doesn’t see local images unless they’re built with sudo. And, running docker with sudo raises other issues/concerns.

@fantasy4 I think for your issue, you have two options.

  1. Either add your username to “docker” group. This will allow you to run docker in privileged mode.
  2. Or run the daemon in rootless mode.

Hope this helps.