simplycoding
simplycoding

Reputation: 2967

Having trouble with installing Docker on Window's Ubuntu WSL

I'm in the middle of installing Docker on Windows' Ubuntu WSL but having trouble. Here's the installation guide: https://docs.docker.com/engine/install/ubuntu/

The specific error I'm getting when I try to run the command at the end (sudo docker run hello-world) is: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock.

I went through all the steps but didn't get any errors until the end and got that error, but I don't think step 2 was done properly. Is this command supposed to output anything?

echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

If so, what should it output? I'm asking since I see the echo command. Or is it just piping that output to the second command? What's the best way to see which step succeeded or failed in this installation process? I'm not familiar enough to triage what's going wrong

Upvotes: 3

Views: 2706

Answers (1)

NotTheDr01ds
NotTheDr01ds

Reputation: 20628

You are installing Docker Engine directly on Ubuntu WSL, which is fine, but I want to be sure you understand that you have another option. The "recommended" method is to install Docker Desktop for Windows.

Docker Desktop does provide a few additional features over the base Docker Engine:

  • 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.

Both versions run the same engine underneath, but Desktop just provides those additional convenience features as well. If you don't need or want these, and you really do want to just install Docker Engine, then the solution to your current issue should be to just run:

sudo service docker start

Then try the sample again. It's an extra step that's required in WSL that isn't covered in the Docker doc.

(Bonus tip) I recommend running hello-world via:

sudo docker run --rm hello-world

There's no reason to leave that particular container hanging around after it exits, IMHO. I wish Docker would update those docs.

Also, assuming everything works at that point, I recommend getting rid of that image via:

sudo docker rmi hello-world

Explanation:

On "regular" Ubuntu, part of the installation process performed by the docker-ce package is to start the Docker daemon. However, that step fails due to differences in the way WSL works (lack of runlevels, systemd, startup script support, etc).

So when you get to that (currently) Step 3 to verify that the daemon is running via docker run ..., it's not.

You're also going to run into a similar issue when you get to the section "Post-installation steps for Linux: Configure Docker to start on boot"*

This won't work on WSL, since there's no concept of a "boot" (and, again, no Systemd). So you'll need an alternate method to make sure the engine is running in WSL. That can, of course, simply be a manual sudo service docker start when you need it. Or you can, if you'd like, add something like the following to your ~/.bashrc:

wsl.exe -u root -e sh -c "service docker status || service docker start"

There are other methods as well, but that's just one example.

As for the lack of any output when adding the repository key, that's expected since the output (Stdout) is piped to /dev/null. If there was an error, it would likely still be reported on Stderr.

Upvotes: 3

Related Questions