An Error Despite Having Configured WSL2 in Docker Desktop

Docker Desktop had to be running


Posted on Sat, Nov 4, 2023
Tags docker, windows
docker, windows
📝 This article is a translation of the original Japanese post. View original

The command 'docker' could not be found in this WSL 2 distro Even Though WSL2 Is Configured in Docker Desktop

On Ubuntu under WSL2, I was getting:

1
2
3
4
5
6
7
8
$ docker build                                                                                                                                                                                         (git)-[main] 

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/

Of course I had already followed Docker Desktop WSL 2 backend on Windows | Docker Docs.

Running the wsl command from the command prompt:

1
2
3
4
5
C:\Users\am>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

What is this “Stopped”? I wondered — maybe Docker Desktop also boots a WSL2 VM?

1
2
3
4
5
6
7
# after starting docker desktop

C:\Users\am>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Now they are Running. Let’s run the docker command in WSL2.

1
2
3
$ docker images                                                                                                                                                                                        (git)-[main] 
REPOSITORY                                                                                       TAG                                                                          IMAGE ID       CREATED         SIZE
hubproxy.docker.internal:5555/docker/desktop-kubernetes                                          kubernetes-v1.28.2-cni-v1.3.0-critools-v1.28.0-cri-dockerd-v0.3.4-1-debian   1d7e8203bdb9   3 weeks ago     430MB

Well, obviously.

To summarize:

  • Unless Docker Desktop is started, the docker-desktop VM on WSL2 is not running
  • As a result, even though the docker command should be runnable, you get the error The command 'docker' could not be found in this WSL 2 distro

Share