How to remove Docker distros from WSL?

I've installed Docker Desktop and Ubuntu 20.04 [Microsoft Store] on Windows 10 and see that I have three distros [below], but I want to get rid of docker-desktop and docker-desktop-data, as I don't need so many of them and want to use Ubuntu-20.04 for my Docker experiments only:

PS $ wsl -l -v

  NAME                    STATE           VERSION
  Ubuntu-20.04            Running         2
  docker-desktop-data     Running         2
  docker-desktop          Running         2
  • I know docker-desktop-data contains images and docker-desktop contains the Docker infrastructure, but it's still unclear to me and confusing

How do I delete these and do I need them?


Solution 1:

I mentioned this yesterday in a comment on Stack Overflow, but I've now had a chance to try it out, and it works as expected ...

Docker Engine will run just fine in a single WSL2 instance (with one known caveat, see below for workaround), and it sounds like that's what you really want.

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.

If you don't need those features, then:

  • Backup any volumes and images from your existing Docker Desktop installation
  • Uninstall Docker Desktop (the two referenced docker-desktop.* instances will be removed)
  • Optional, but recommended: Reboot Windows, or at least wsl --shutdown
  • Install Docker Engine in the Ubuntu instance per the normal instructions. For the purposes of this answer, use the "Install from a package" and just do steps 1 and 2 for now. The docker run example won't work yet.
  • The normal Docker package installation will attempt to start the daemon, but that doesn't work on WSL since there's no concept of runlevels, startup scripts, systemd, etc. You'll need to manually start it via sudo service docker start.
  • Now you can run the example sudo docker run --rm hello-world (why the Docker doc doesn't have --rm in it makes no sense to me). And clean it up with sudo docker rmi hello-world (also should be part of the doc, IMHO).
  • Continue to the Post-Installation steps to allow your normal user to be able to run Docker without sudo.

After that, the next step in the Docker doc is to enable it to run on boot. This won't work on WSL, since there's no concept of a "boot". 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.