skip to Main Content

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.

5

Answers


  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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
  4. "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
    
    Login or Signup to reply.
  5. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search