docker: unrecognized service when installing CUDA

Solution 1:

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.