skip to Main Content

Exactly the same problem as Ubuntu WSL with docker could not be found

$ docker

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

See https://docs.docker.com/docker-for-windows/wsl/ for details.

But my requirement is different — I want to

  • stick with WSL1 (for reasons beyond this topic)
  • and use Docker for Windows as-is

I.e., I have WSL1 and Docker for Windows installed parallel to each other. This is my current info:

C:> ver
Microsoft Windows [Version 10.0.18363.1379]

C:> wsl -l -v
  NAME      STATE           VERSION
* Debian    Running         1

I don’t see integration in "Resources -> WSL Integration", and I don’t have WSL2 backend enabled in Docker Desktop settings.

enter image description here

Just that I’m getting the above problem — my docker works anywhere, in CMD, Powershell, git-bash, etc, just not in my WSL.

All solutions that I found are to install Docker for Windows within WSL1 or WSL2, but I want to keep everything as is — WSL and Docker for Windows installed parallel to each other.

Any solution for that?

3

Answers


  1. Chosen as BEST ANSWER

    Just FTA, this is the quick hacky workaround that I found, while trying to solve it myself

    Change the C:Program FilesDockerDockerresourcesbindocker file to

    #!/usr/bin/env sh
    #
    # Copyright (c) Docker Inc.
    
    binary=$(basename "$0")
    "$binary.exe" "$@"
    

    Then docker can work anywhere now, in CMD, Powershell, git-bash, and as well as WSL1.

    Note that this hacky workaround is specially for the situation described in OP, might not work for anything else.


  2. The command ‘docker’ could not be found in this WSL 1 distro.
    We recommend to convert this distro to WSL 2 and activate
    the WSL integration in Docker Desktop settings.

    This means in WSL2, it has a real linux kernel which is required to install docker daemon, then in docker-desktop you could have chance to set docker daemon in WSL2. Otherwise, the docker daemon is running in Hyper-V machine. But, if you stick in WSL1, no chance to run docker-daemon in WSL, so the only option is running docker daemon in Hyper-V machine.

    Although above is the fact, still we have chance to let you operate docker ps, docker pull etc. in WSL1 bash just like you operate through CMD, Powershell, git-bash, that is allow Docker to accept requests from remote hosts.

    For your case, the steps maybe next:

    1. Expose docker daemon in docker desktop settings as next, then click Apply & Restart:

    enter image description here

    2. Install standalone docker client in WSL1:

    $ wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
    $ tar zxvf docker-20.10.5.tgz
    $ cd docker
    

    3. Set default docker daemon:

    $ export DOCKER_HOST=tcp://localhost:2375
    

    4. Verify docker client command:

    $ ./docker info
    
    Login or Signup to reply.
  3. I ran into the same issue with Ubuntu 20 Distro when trying to use Docker. Below are steps I followed to resolve it:

    1- I went to microsoft Store and downloaded a recent distro version of the distro, that was Ubuntu 22.04

    2- On powershell as admin, I ran the command wsl -l -v to make sure I have the new version

      PS C:WINDOWSsystem32> wsl -l -v
      NAME                   STATE           VERSION
    * Ubuntu                 Stopped         1
      Ubuntu-22.04           Stopped         2
      docker-desktop-data    Stopped         2
      docker-desktop         Stopped         2
    

    3- I ran the command: wsl –set-default Ubuntu-22.04 to use wsl 2

    I was now able to use Docker on WSL 2

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