LoginSignup
0
0

More than 1 year has passed since last update.

Ubuntuとdockerをwsl2で再連携

Last updated at Posted at 2022-09-07

Ubuntu18.04から
Ubuntu20.04に乗り換えた際につまずいた
wslとdockerについての手順です。

環境

windows10
Ubuntu18.04-> Ubuntu20.04(両方入っている状態)
docker
wsl

事象

Ubuntu-20.04をインストールしたのち
ubuntu-20.04を起動しdockerコマンドを適当にいれたらエラーが発生した。

ubuntu-20.04
>docker ps

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.

For details about using Docker Desktop with WSL 2, visit:

https://docs.docker.com/go/wsl2/

要約すると
現在のUbuntu-20.04のwslは1なので
dockerを使用するならwsl2にしてくださいね

ということ。

現状の設定確認

コマンドプロンプトを開き
wsl -l -v
と入力すると現在のwslの設定が確認できる

コマンドプロンプト
>wsl -l -v

  NAME         STATE   VERSION
* Ubuntu-18.04 RUNNING 2
  Ubuntu-20.04 RUNNING 1

Ubuntu-20.04はやはり1。
あと、主で利用するものが
Ubuntu-18.04になっているのでこれを
Ubuntu-20.04にする

コマンドプロンプト
// 主で使用するものを設定
>wsl --set-default Ubuntu-20.04
// wslを2に設定
>wsl --set-version Ubuntu-20.04 2
>wsl -l -v

  NAME         STATE   VERSION
* Ubuntu-20.04 RUNNING 2
  Ubuntu-18.04 RUNNING 2

すると、dockerの
settings Resources WSL Integrationに
Ubuntu-20.04が表示されるようになる

docker_setting.png

このUbuntu-20.04にチェックを入れてやる

最後に

Ubuntu-20.04およびdockerを再起動(windows毎再起動なら確実)すれば
Ubuntu-20.04にてdockerにアクセスできるようになる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0