44

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

ant31
  • 4,471
  • 4
  • 15
  • 20
  • 1
    Could you please give me a reference link where it is suggested to use WSL2+docker desktop windows, instead of directly install docker on the WSL2 distro ? – AnjK Feb 18 '21 at 14:23
  • 1
    @AnjanaAK Both the [Docker](https://docs.docker.com/desktop/windows/wsl/) and [Microsoft](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers) directions for installing/using Docker in WSL are to use Docker Desktop. – NotTheDr01ds May 01 '22 at 00:38

5 Answers5

34

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.

jmaitrehenry
  • 2,190
  • 21
  • 31
  • Thank you, so there isn't any performance or problem to consider by doing docker directly in the wsl2? I don't have strong usecase for windows container/ide integration and found few limitations around network (port forward is possible but not directly reaching the container ip). – ant31 May 21 '20 at 10:18
  • 2
    Docker on WSL2 should have the same performance as Docker Desktop using WSL2 (as they use the WSL2 for running the docker daemon). – jmaitrehenry May 21 '20 at 13:23
  • 3
    There is, at least in my tests, a decrease in memory consumption (five times less) if running docker inside WSL without docker desktop. – phd_coder Jan 26 '21 at 13:17
  • @jmaitrehenry When using WSL2+docker-for-windows with WSL integration, do we need to install docker CLI seperately on WSL2? If we does that, will it cause any conflicts? – AnjK Feb 18 '21 at 14:25
  • Also, you have to [pay](https://www.docker.com/pricing/) for Docker Desktop now if you are enterprise. – Chris Collett Sep 09 '22 at 17:22
  • why to use wsl then? why not use only docker desktop? – jairhumberto May 08 '23 at 02:21
15

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.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
7

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.

HaiTH
  • 925
  • 9
  • 9
  • 2
    I cannot test it as I have not installed Docker Desktop. It is just that many tutorials are based on Docker Desktop and this starts to confuse you as soon as you have to start docker at all: the distro [does not know systemd / systemctl](https://stackoverflow.com/questions/65813979/sudo-systemctl-enable-docker-not-available-automatically-run-docker-at-boot-o), and you have to use service start docker instead (in my case). And following guides about the right host IP is also different in a Linux or Windows shell of course. Now that I started it, I also finish it with docker inside WSL2 :). – questionto42 Feb 06 '21 at 11:28
  • 1
    Have some of these pain points been resolved since this post? – Corgalore Jun 15 '22 at 21:48
0

Not so sure about the performance difference, but the compatibility is better when using Docker directly in the WSL2 distro (without Docker Desktop). For example, this problem I've been fighting for almost a year is still unaddressed and a pita.

If you are used to Linux environment, using Docker without Docker Desktop could be a better option when compatibility is the concern.

ffyuanda
  • 11
  • 2
-2

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.

Avinash Singh
  • 3,421
  • 2
  • 20
  • 21