【Docker】コマンドをたたいた時エラーメッセージ「The command ‘docker’ could not be found in this WSL 2 distro.」が表示されたときの原因と解決策をお伝えします

こんにちは。たいら(@tairaengineer2)です。
転職を繰り返し現在5社経験している、14年目エンジニアです。

この記事では、dockerのコマンドを実行したとき

Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策
というエラーメッセージが表示されたときの原因とその解決策をお伝えします。

前提:実行環境

実行環境は以下の通りです。

OS Windows11
Dockerのバージョン 28.0.4

エラーメッセージ「The command ‘docker’ could not be found in this WSL 2 distro.」が表示される原因

エラーメッセージが表示される原因は、Docker Desktopの設定でWSLが有効になっていないことです。
なので、設定してあげればエラーメッセージは表示されなくなります。

エラーメッセージ「The command ‘docker’ could not be found in this WSL 2 distro.」が表示させないようにする解決策

Docker Desktopを開き、上部バーにある歯車アイコンを選択します。
Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策

左のタブの【Resource】を選択します。
Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策

表示されるリストの中から【WSL Integration】を選択します。
Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策

【Enable integration with additional distros:】【Ubuntu】がオフになっているので、オンにします。
【Apply & restart】を選択します。
Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策

以上で設定は完了です。
dockerコマンドをたたいてみると、正常に結果が返ってくることが確認できます。

Dockerのコマンドをたたいた時「The command 'docker' could not be found in this WSL 2 distro.」が表示されたときの原因と解決策

まとめ:エラーメッセージ「The command ‘docker’ could not be found in this WSL 2 distro.」が表示されたときはxml宣言の前を確認しよう!

以上がエラーメッセージ「The command ‘docker’ could not be found in this WSL 2 distro.」が表示されたときの原因と解決策でした!

あなたのご参考になったのなら、とても嬉しいです(*´▽`*)
ではでは~(・ω・)ノシ

コメント

タイトルとURLをコピーしました