OS Windows WSL

Docker Desktop を WSL2 で使う (Windows 10)

2020年3月10日

Docker Desktop が、WSL2 で使えるようになったので、試して見ます。

筆者の環境は Windows 10 Professional ですが、Homeでも大丈夫のはずです。

Docker Desktop for Windows では、Hyper-V (Windows 10 Professional が前提)を前提としてましたが、Docker Desktop for Windows + WSL2 の場合は、Hyper-V無しでも動くようになります。

使用した Docker Desktop は、Version 2.2.0.3になります。

1.コンポーネントのインストール

Using Docker in WSL 2 に以下をインストールするようにあるので、必用なコンポーネントをインストールします。

もともと WSL を使っていれば、WSL2 は、他の MS のコンポーネントの様に自然に Windows Updateされて WSL2になっているのかなと思ったら、WSL1 の時に入れていると WSL 1 のままになっていました。

WSL1の場合は、Power Shell から明示的に WSL2にアップグレードする必用があります。

アップグレードの仕方は「Install the Docker WSL 2 Technical Preview.」に書いてあります。

wsl -l -v で確認すると、Ubuntu-18.04 が VERSION 1 のままです。

wsl --set-version Ubuntu-18.04 2  (わかりにくいですが、最後に「2」と入れています)で WSL 2 にアップグレードできます。

なお WSL1 と WSL2 は併存できるそうです。(併存させる必要はあまりない気もしますが)

2. Docker Desktop の設定を行う

ここと・・・

こちらを選択して「Apply & Restart」をクリックします。
(WSL2 のものだけ見えます。WSL1だとここにリストされません

3. 確認

WSL2 に変換した、Ubuntu の WSL を立ちあげて、適当なコンテナが動くか確認します。

yuhki@yuhki-legion:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

yuhki@yuhki-legion:~$

hello-world コンテナが動いてたので問題なさそうです。

私の環境は Hyper-V が動くので Hyper-V を確認してみます。

Hyper-V 上では仮想マシンは起動していません。これまでの Docker for Windows のように「Moby Linux VM」は存在しません。

WSL2だけで、docker が動いているのがわかります。

ただし、細かく言うと WSL2 は、ダウンロードした Linux ディストリビューション毎に、Hyper-V ハイパーバイザー上で、軽量な 「Utility VM」と呼ばれる VM を動かすようになりました。

「Utility VM」は、Hyper-V マネージャー上には表示されないVMです。(参考:「完全なLinuxがWindows 10上で稼働する? 「WSL 2」とは」)

-OS, Windows, WSL

Copyright© エンジニアの何でもメモ帳 , 2024 All Rights Reserved.