Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu Error "The command 'docker' could not be found in this WSL 2 distro."

I'm running WSL 2 on Ubuntu and having some issues getting docker up and running on my computer. I have Docker Desktop installed and running in the background, and I also have WSL integration enabled with Ubuntu.

When I try to run simple docker commands, such as docker --version, I receive this error:

The command 'docker' could not be found in this WSL 2 distro. We recommend to activate the WSL integration in Docker Desktop settings.

For details about using Docker Desktop with WSL 2, visit:

https://docs.docker.com/go/wsl2/

I have already visited the link and followed all the instructions it gives, enabling WSL integration with Ubuntu as shown here:

Docker Desktop Settings screenshot

However the error I receive is still the same. Does anyone know how to fix this?

Note: I can run Docker commands (such as docker --version) in PowerShell and Command Prompt, but it is unrecognized in Ubuntu.

like image 462
Adrian McBroom Avatar asked Dec 06 '25 17:12

Adrian McBroom


2 Answers

I was having this problem, so I went to this docker link (your link is broken) and worked through the suggestions.

This worked for me:

  1. In PowerShell, type wsl -l -v and you should get something like this:

      NAME                   STATE           VERSION
    * Ubuntu                 Running         2
      docker-desktop         Running         2
      Ubuntu-20.04           Running         2
      docker-desktop-data    Running         2
    
  2. Go into the Docker Desktop Settings -> Resources -> WSL integration.

  3. Select the WSL 2 distro you are using from the above list (e.g. Ubuntu 20.04 in my case) and Apply & Restart.

Now running the version command works as expected in my distribution, and I have all of the functionality required from within the WSL terminal.

:~$ docker -v

Docker version 20.10.16, build aa7e414

like image 190
jimjam100 Avatar answered Dec 09 '25 11:12

jimjam100


"Docker Desktop" should integrate into WSL without additional configuration. Especially, it should not be necessary to append folders to the PATH environment variable.

Of course it must be made sure that "Docker Desktop" as well as the certain WSL distribution are set up for WSL2: In "Docker Desktop" settings "General/Use the WSL2 based engine" must be checked and wsl -l -v should list version 2. If the latter is not true, it can be fixed by wsl --set-version <distribution> 2, where <distribution> is the name from the previous list. Note that "Ubuntu" and "Ubuntu-22.04" (for example) are different.

"Docker Desktop" normally integrates with the default distribution. It can be seen from the asterisk in wsl -l -v which one had been chosen. For me this once was set to "docker-desktop-data" (probably because "Docker Desktop" had been installed earlier than the distribution). The default distribution can be changed by wsl --set-default <distribution>. Furthermore, in "Resources/WSL integration" of "Docker Desktop" settings, the option "Enable integration with my default WSL distro" must be set.

If another distribution than the default one should use docker as well, it needs to be selected explicitely in the list of distributions of "Resources/WSL integration". Press "Refresh" if that other distribution had been installed recently while "Docker Desktop" was already running.

"Integration" means, as far as I can tell, that a link /usr/bin/docker, pointing to /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker, is created automatically. Since /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker seems to be available in all distributions regardless of the integration setting, the presence (or not) of /mnt/wsl/docker-desktop/cli-tools/usr/bin and its content might help to analyse the problem. There should be docker, docker-compose and others:

ls -l /usr/bin/docker
ls -l /mnt/wsl/docker-desktop/cli-tools/usr/bin
like image 34
JeffRSon Avatar answered Dec 09 '25 11:12

JeffRSon