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

7

13

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.

Povertystricken answered 3/6, 2022 at 0:44 Comment(3)
You really should include the output of wsl -l -v.Undersea
@JeffRSon, Apologies, still learning StackOverflow etiquette. The output on my system shows Ubuntu 22 (posted below)Diaconicum
@Diaconicum No worries - I'm not even sure what the right way to handle it is. Either we have you edit the "dupe" question or post an answer here (as you currently) have. Neither is optimal, but let's go with it for now while we try to figure it out. Then we can "clean it up" later.Pommard
C
8

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

Chemulpo answered 23/6, 2022 at 13:43 Comment(0)
U
6

"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
Undersea answered 19/7, 2022 at 7:14 Comment(1)
Thanks. Not sure what the solution is, but you helped me find the gap. My /wsl folder is nested inside /mnt/host for some reason. Docker is in /mnt/host/wsl/docker-desktop/cli-tools/usr/bin.Cap
K
2

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

Instead of docker -v or wsl -v, try docker.exe -v and wsl.exe -v

(This, of course, after turning on your distro in Docker)

Keeping answered 14/12, 2023 at 16:40 Comment(1)
do you know why it is the case?Gantline
R
1

Try to put following line in your Ubuntu's ~/.bashrc

PATH+=":/mnt/c/Program Files/Docker/Docker/Resources/bin"

( It might be /c/Program Files/... depending on your mount point. You can check with the command df )

and start a new bash shell, then run docker.

Redaredact answered 22/6, 2022 at 22:42 Comment(0)
A
0

I was able to fix this by taking the below steps but it required some work arounds because I was unable to click-install the necessary WSL2 Linux kernel update after downloading.

Then I had to complete this process.

Then I had go to the PowerShell command line and navigate to the location of the above WSL Update and run the following (in administrator mode-- and not in the Linux command line):

& '.\wsl_update_x64.msi'

That was the only way I could successfully install the update

Then at Powershell command line (in administrator mode-- and not the linux command line), I ran

wsl --set-version Ubuntu 2

per instructions here

Afire answered 24/6, 2022 at 19:19 Comment(0)
K
0

Today I had this problem too. In WSL I got a message that I could update WSL from the microsoft store. So I updated WSL and after that moment docker wasn't on my PATH anymore.

It was a lazy saturday morning, so I decided to restart my PC. And magically the problem was "fixed".

Maybe it would be enough to restart WSL distro, at this moment I don't have the time to research whether that would be a good solution.

Kaylor answered 15/10, 2022 at 8:7 Comment(0)
E
0

I had exactly the same error after switching from Docker-Desktop to Rancher-Desktop with WSL 2 Ubuntu 22.04 LTS:

> wsl docker version

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 solved it with

  1. Uninstalling Docker-Desktop (Important!)
  2. Setting WSL Version to 2. E.g. with wsl --set-version Ubuntu 2
  3. Enabling WSL Integration in Rancher-Desktop Preferences

enter image description here

Eaglet answered 22/2 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.