Unable to install cuda (11.3) inside Ubuntu docker environment

Hello Forums! I’m trying to get the cuda toolkit installed in a docker environment but every time I get to the point of issuing apt-get install cuda it runs for a while, then spits out:

Selecting previously unselected package xserver-xorg-legacy.
Preparing to unpack .../418-xserver-xorg-legacy_2%3a1.20.9-2ubuntu1.2~20.04.2_amd64.deb ...
Unpacking xserver-xorg-legacy (2:1.20.9-2ubuntu1.2~20.04.2) ...
Errors were encountered while processing:
 /tmp/apt-dpkg-install-Klzpwz/110-nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb
 /tmp/apt-dpkg-install-Klzpwz/115-nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
#

From then on, my apt-get in that docker returns this type of message:

# sudo apt-get install cuda
Reading package lists... Done
Building dependency tree
Reading state information... Done
cuda is already the newest version (11.3.1-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 cuda-drivers-465 : Depends: nvidia-compute-utils-465 (>= 465.19.01) but it is not going to be installed
                    Depends: nvidia-utils-465 (>= 465.19.01) but it is not going to be installed
 nvidia-driver-465 : Depends: nvidia-compute-utils-465 (= 465.19.01-0ubuntu1) but it is not going to be installed
                     Depends: nvidia-utils-465 (= 465.19.01-0ubuntu1) but it is not going to be installed
                     Recommends: libnvidia-compute-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
                     Recommends: libnvidia-decode-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
                     Recommends: libnvidia-encode-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
                     Recommends: libnvidia-ifr1-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
                     Recommends: libnvidia-fbc1-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
                     Recommends: libnvidia-gl-465:i386 (= 465.19.01-0ubuntu1) but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
#

And if I try the --fix-broken-install option it returns this:

# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  nvidia-compute-utils-465 nvidia-utils-465
The following NEW packages will be installed:
  nvidia-compute-utils-465 nvidia-utils-465
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
417 not fully installed or removed.
Need to get 0 B/470 kB of archives.
After this operation, 1518 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 file:/var/cuda-repo-ubuntu2004-11-3-local  nvidia-compute-utils-465 465.19.01-0ubuntu1 [106 kB]
Get:2 file:/var/cuda-repo-ubuntu2004-11-3-local  nvidia-utils-465 465.19.01-0ubuntu1 [364 kB]
(Reading database ... 114185 files and directories currently installed.)
Preparing to unpack .../nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb ...
Unpacking nvidia-compute-utils-465 (465.19.01-0ubuntu1) ...
dpkg: error processing archive /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb (--unpack):
 unable to make backup link of './usr/bin/nvidia-cuda-mps-control' before installing new version: Invalid cross-device link
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb ...
Unpacking nvidia-utils-465 (465.19.01-0ubuntu1) ...
dpkg: error processing archive /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb (--unpack):
 unable to make backup link of './usr/bin/nvidia-debugdump' before installing new version: Invalid cross-device link
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb
 /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
#

Is this problem on my side? If it is anyone know how to resolve it?

Thanks,
-Greg

I found this poor soul from 6 months ago with the same question and it was unanswered. I also found some various articles (1,2) about people experiencing the Invalid cross-device link error who were able to use dpkg --force-overwrite switches to resolve. When I do that it continues to fail:

# apt-get -o Dpkg::Options::="--force-overwrite" install --fix-broken
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  nvidia-compute-utils-465 nvidia-utils-465
The following NEW packages will be installed:
  nvidia-compute-utils-465 nvidia-utils-465
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
417 not fully installed or removed.
Need to get 0 B/470 kB of archives.
After this operation, 1518 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 file:/var/cuda-repo-ubuntu2004-11-3-local  nvidia-compute-utils-465 465.19.01-0ubuntu1 [106 kB]
Get:2 file:/var/cuda-repo-ubuntu2004-11-3-local  nvidia-utils-465 465.19.01-0ubuntu1 [364 kB]
(Reading database ... 114185 files and directories currently installed.)
Preparing to unpack .../nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb ...
Unpacking nvidia-compute-utils-465 (465.19.01-0ubuntu1) ...
dpkg: error processing archive /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb (--unpack):
 unable to make backup link of './usr/bin/nvidia-cuda-mps-control' before installing new version: Invalid cross-device link
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb ...
Unpacking nvidia-utils-465 (465.19.01-0ubuntu1) ...
dpkg: error processing archive /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb (--unpack):
 unable to make backup link of './usr/bin/nvidia-debugdump' before installing new version: Invalid cross-device link
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-compute-utils-465_465.19.01-0ubuntu1_amd64.deb
 /var/cuda-repo-ubuntu2004-11-3-local/./nvidia-utils-465_465.19.01-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
#

I found something amiss on my OS configuration! In my /usr/local/ directory I had this:

$ ls /usr/local/ -la
total 48
drwxr-xr-x 12 root root 4096 Jun 19 17:58 .
drwxr-xr-x 14 root root 4096 Jul 31  2020 ..
drwxr-xr-x  2 root root 4096 Jun 19 17:58 bin
drwxr-xr-x  2 root root 4096 Jun 19 16:51 cuda
lrwxrwxrwx  1 root root   25 Jun 19 17:58 cuda-11 -> /etc/alternatives/cuda-11
drwxr-xr-x 15 root root 4096 Jun 20 05:26 cuda-11.3
drwxr-xr-x  2 root root 4096 Jul 31  2020 etc
drwxr-xr-x  2 root root 4096 Jul 31  2020 games
drwxr-xr-x  2 root root 4096 Jul 31  2020 include
drwxr-xr-x  4 root root 4096 Dec  4  2020 lib
lrwxrwxrwx  1 root root    9 Sep  4  2020 man -> share/man
drwxr-xr-x  2 root root 4096 Jul 31  2020 sbin
drwxr-xr-x  7 root root 4096 Jul 31  2020 share
drwxr-xr-x  2 root root 4096 Jul 31  2020 src
$

Then, looking into the bare /usr/local/cuda directory, there was a lone softlink:

$ ls /usr/local/cuda -la
total 8
drwxr-xr-x  2 root root 4096 Jun 19 16:51 .
drwxr-xr-x 12 root root 4096 Jun 19 17:58 ..
lrwxrwxrwx  1 root root   20 Jun 19 16:51 cuda-11.3 -> /usr/local/cuda-11.3
$

Everything from the cuda installation was actually located in the cuda-11.3 directory and you can see that the /usr/local/cuda directory has a single pointer to cuda-11.3 but this architecture is wrong. I think that /usr/local/cuda should be a link pointing to /usr/local/cuda-11.3. When I updated that, everything started working!