Score:0

docker: unrecognized service when installing CUDA

WSL2 Ubuntu 20.04.3 LTS kernel image: 5.10.60.1-microsoft-standard-WSL2

I am trying to install CUDA according to the instructions here: https://ubuntu.com/blog/getting-started-with-cuda-on-ubuntu-on-wsl-2

And I am getting a docker: unrecognized service message when running command sudo service docker stop. I did follow the instructions up to the point where this command is in the tutorial, and the results of running sudo apt update && sudo apt install -y nvidia-docker2 seem successful. I've also tried to check if the docker service is available at all using service --status-all and didn't see it in the results.

Please help me figure out how to properly install CUDA, I am trying to set up opencv with GPU support for a project I am working on in image processing.

Here are the outputs from the mentioned commands I ran:

 service --status-all

Output:

 [ - ]  apparmor
 [ ? ]  apport
 [ - ]  atd
 [ - ]  console-setup.sh
 [ - ]  cron
 [ ? ]  cryptdisks
 [ ? ]  cryptdisks-early
 [ - ]  dbus
 [ ? ]  hwclock.sh
 [ + ]  irqbalance
 [ - ]  iscsid
 [ - ]  keyboard-setup.sh
 [ ? ]  kmod
 [ - ]  lvm2
 [ - ]  lvm2-lvmpolld
 [ - ]  multipath-tools
 [ + ]  open-iscsi
 [ - ]  open-vm-tools
 [ ? ]  plymouth
 [ ? ]  plymouth-log
 [ - ]  procps
 [ - ]  rsync
 [ - ]  rsyslog
 [ - ]  screen-cleanup
 [ - ]  ssh
 [ ? ]  ubuntu-fan
 [ + ]  udev
 [ - ]  ufw
 [ - ]  unattended-upgrades
 [ - ]  uuidd
 [ - ]  x11-common

Command:

sudo apt update && sudo apt install -y nvidia-docker2

Output:

Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 https://nvidia.github.io/libnvidia-container/experimental/ubuntu18.04/amd64  InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64  InRelease
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:7 https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/amd64  InRelease
Hit:8 https://nvidia.github.io/nvidia-docker/ubuntu18.04/amd64  InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-docker2 is already the newest version (2.8.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
NotTheDr01ds avatar
vn flag
It sounds like something may have gone wrong during the `sudo apt -y install docker.io` step. Do you see any errors related to this with `less -r /var/log/apt/term.log`?
יחזקאל הירשהורן avatar
@NotTheDr01ds maybe this: dpkg: warning: while removing linux-modules-5.4.0-81-generic, directory '/lib/modules/5.4.0-81-generic' not empty so not removed ???
Score:1
vn flag

I've been able to reproduce this using the (apparently outdated) Canonical instructions you linked.

You can see the problem in /var/log/apt/term.log during the installation of the docker.io package:

invoke-rc.d: unknown initscript, /etc/init.d/docker not found.

That's the same init script that the service command attempts to run. Presumably, it was removed from the docker.io package sometime between the time the instructions were written (and presumably valid) and now. That's no surprise, really. Ubuntu uses Systemd, and the docker.io installs the Systemd unit file for the Docker service. Many packages used to also provide the legacy init script.

However, WSL doesn't support Systemd (without a lot of hackery, at least). It's much better to have a Docker version that provides an init script for the service command. Either that, or one that knows how to start on its own under WSL.

So let's start by uninstalling docker.io and the dependencies it installed:

sudo apt remove docker.io
sudo apt autoremove

Then you have two options. Either:

  • Install Docker Desktop for Windows. Docker Desktop has tight integration with WSL, and provides some nice-to-have features that you don't get with the open-source Docker version:

    • It can be shared amongst multiple WSL2 instances
    • It can run from PowerShell and CMD
    • It provides a GUI dashboard of containers and volumes
    • It handles automatic upgrades (although some might not consider that necessarily an advantage)
    • It's a convenience method that handles all of the other stuff below automatically for you.

    There has been a license change recently that requires a paid subscription if you are using it in a large company. Some folks seem to be wanting to move away from it as a result, but I would propose (purely my opinion) that if you work for a large company, they will often pay for these sorts of tools. And that, in turn, helps fund Docker's open-source initiatives.

  • However, if you do want to use the open-source edition, you can do that using (mostly) the official Docker instructions for Ubuntu.

    Those instructions do assume that the installation script will start the Docker daemon. However, it attempts to use Systemd, which fails on WSL. But now it does provide the init.d script, so you can now run sudo service docker start as you originally tried.

    Alternatively, nVidia provides setup instructions which use the get.docker.com script.

יחזקאל הירשהורן avatar
Thanks! If I understand correctly, the nVidia link you gave is the only one that will get me through the entire process up to using tensorflow (I am actually interested in opencv, but I guess it does use tensorflow under the hood, or something similar)?
NotTheDr01ds avatar
vn flag
@יחזקאלהירשהורן I haven't tried any of the GPU compute features myself yet, but it's something I'd like to do eventually. Yes, the nVidia instructions seem to be the most "complete", but if I was doing it, I'd probably skip their instructions for installing Docker. I'd try it with Docker Desktop, and pick up with their step on installing the `nvidia-docker2` package. That said, I can't guarantee it will work. But you can always uninstall Docker Desktop and then pick up with their Docker installation instructions if something goes wrong.
יחזקאל הירשהורן avatar
Thanks. I did use their instructions in the end, and it worked. In the future I will probably try your suggestion with Docker Desktop because I guess there is a good reason you and other people say it works better, and I will eventually need it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.