WSL2 で Docker Desktop で WSL2 設定しているのにエラーになる件

Docker Desktop 起動が必要だった


Posted on Sat, Nov 4, 2023
Tags docker, windows

Docker Desktop で WSL2 の設定しているのに The command 'docker' could not be found in this WSL 2 distro が出る

WSL2 の Ubuntu にて、

$ 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/

が出ている。もちろん、Docker Desktop WSL 2 backend on Windows | Docker Docs は実施している。

コマンドプロンプトにて、wsl コマンドを実行する

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

Stopped とはなんだ? と思ったが、これもしかして、Docker Desktop でも WSL2 の VM 起動しているのかな?

# docker desktop 起動後

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

Running になった。WSL2 で docker コマンドを実行する。

$ 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

まあ、当たり前ですよね。

まとめると、

  • Docker Desktop を起動しないと WSL2 の docker-desktop VM が起動していない
  • 結果として、docker コマンドは実行できるが、 The command 'docker' could not be found in this WSL 2 distro というエラーが出る?