'Difference between "WSL2+docker desktop windows" and directly install docker on the WSL2 distro?

Why is it recommended to run WSL2+docker desktop windows, instead of directly install docker on the WSL2 distro ?

It seems that both work but I read that the way to go is with docker desktop, I'm trying to understand why.

Thank you



Solution 1:[1]

The main difference between using Docker Desktop with the WSL2 integration and using docker directly in WSL2 without Docker Desktop is the level of integration with your tools.

When you use Docker desktop, you have access to docker in powershell/cmd, have access to your file on windows, the possibility to switch to Windows container and to use it with your IDE.

If you install docker inside your WSL2 distro, docker will not be accessible from Windows directly.

Solution 2:[2]

Although all the benefits pointed out in approved answer sound interesting. I recommend to use docker-ce inside WSL directly instead of Docker for Desktop. It's too buggy at the moment.

Even when all the issues had been reported a long time ago. You will often encounter issues losing connection between Windows browser to WSL or connection between your app running inside WSL to Docker for Desktop. Another common issue if shutting down Windows when having Docker desktop is annoying also:

com.docker.wsl-distro-proxy.exe - Application Error
The application was unable to start correctly (0xc0000142).

To be concluded, working with Docker for Desktop Windows is a pain atm.

Solution 3:[3]

Differences between Docker Desktop in Windows and Docker Engine (CE) in a WSL2 instance. Some of these are repeated in other answers, many are not:

Docker Desktop:
  • Adds additional features such as:

    • A dashboard view for Containers, Images, and Volumes
    • (Optional) Automatic update checks and downloads
    • (Optional) Automatically start Docker Desktop upon login to Windows
    • (Optional) built-in Kubernetes local cluster provided by the docker-desktop instance is available to all shells (WSL shells, PowerShell, and CMD.
    • (In Preview) Dev Environments which, if I'm summarizing correctly, encapsulate code and services together in containers that can be easily shared with other team members.
  • The Docker daemon from the Docker Desktop installation be accessed from multiple WSL2 instances, PowerShell, and CMD.

  • Still uses WSL2 by default. docker-desktop and docker-desktop-data WSL instances are created. A single Docker Engine is installed in docker-desktop which is then exposed to the other WSL2 instances. For instance, running ls $(command -v docker) in Ubuntu will show that /usr/bin/docker is a symlink to /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker, and Docker sockets to access the daemon are injected into /var/run in each WSL instance.

  • Can alternatively use a Hyper-V backend on Windows Pro and higher if WSL2 is not able to run on the system.

  • Images, containers, volumes, etc. are contained in the docker-desktop-data WSL2 distribution, which is not directly accessible. Use standard docker commands to export and move data, as is the best practice.

  • Value-added features (over and above Docker Engine and K8S) are closed-source

  • Corporate use requires a paid license (currently starting at $5/month) (see footnote)

  • Seems to track the open-source releases fairly closely, although I haven't paid that much attention to how much time elapses between when a CE release is incorporated into Desktop.

  • As far as I know, there's no way to decouple the Docker Engine release from that of Docker Desktop, so there's no way to rollback to an earlier CE release on the system if needed.

Docker Engine/CE:
  • Can be installed directly into most any WSL2 distribution, as long as that distribution would support Docker Engine in the first place. In other words, while you can create a very basic BusyBox distribution for WSL2 (I've done it), you wouldn't be able to run Docker in it without adding additional dependencies. Most major, full-featured distributions, of course, will have no problem.

  • Open-source

  • Kubernetes must be configured separately

  • Installation requires more in-depth Linux knowledge, along with an understanding of the differences in WSL. For instance, the Docker docs assume Systemd is available and that the package manager starts Docker as soon as it is installed. That isn't the case on WSL2.

  • Images, containers, volumes, etc. are placed in the WSL2 distro into which you've installed CE.

  • Many of the Docker Desktop features can be replicated using the CE version, but it requires manual effort. For instance, there's no reason that you can't create the same type of "shared" environment that can be made available to other WSL2 instances, if you put in the effort.

  • Can always install any release desired, and different WSL2 distributions on your computer can have different Docker Engine/CE releases if needed.


Summary and opinion:

Note that I have no relation to nor financial interest in Docker.

Most users will be best served by Docker Desktop. The pre-integration alone is a timesaver that pays for itself. Windows users who may be less familiar with Linux should almost certainly opt for the Desktop version.

I know the paid model always seems to upset some in the community, but I'd encourage those that do require a paid license to consider:

  • At $60/year, if Docker Desktop saves you even a half hour of time over having to configure Docker Engine, it has likely paid for itself. Not that you make $120/hour (or maybe you do), but your employer expects you to generate productivity at least in that range. Your employer would typically rather pay for tools that make you more productive than having you roll-your-own.

  • If you believe Docker is a worthwhile tool for your organization, then financial support which allows for its continued development and maintenance is also beneficial for your company.

Solution 4:[4]

Docker with WSL2 allows you to run linux containers on windows as it can be installed in WSL for windows directly.

When you are building your application, you can use linux images in your dockerfile whereas if you were installing it without WSL2 then you were limited to using only windows based images as it was installed on windows kernel.

Have a look at https://codingfullstack.com/cloud/docker-installation-wsl2/ if you would like to know more about on how to get this working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jmaitrehenry
Solution 2 HaiTH
Solution 3
Solution 4 Avinash Singh