愛と幻想のアジャイル

道産子ソフトウェアエンジニアの技術メモ

【備忘録】Windows10 Home(Insider Preview)にWSL2、Docker Desktop for Windowsをインストールした

Windows10 Home(Insider Preview) に「WSL2(Windows Subysytstem for Linux)」と「Docker Desktop for Windows」を入れてみただけの備忘録です。

発端 forest.watch.impress.co.jp

前提環境

  • Windows 10 Home: 1903
  • WSLは未インストール

Windows 10 Insider Previewビルドをインストールする

MS公式の手順に従い、Insider Previewをインストール。 Windows Insider

  • スタート > [設定]> [更新とセキュリティ] > [Windows Insider Program] 
  • Windows Insider Program を開始する。
  • プレビュービルドを受け取る頻度は「スロー」を選択
  • PC再起動(数回?)  

WSLを有効化する

WSLのディストリビューション(Ubuntu)をインストール

下記の手順を実施する。

  • Microsoft Storeを起動
  • 検索ボックスに「WSL」と入力
  • 検索結果から「Ubuntu」を選択
  • 「入手」ボタンをクリックでインストール実行
  • インストール完了まで待つ
  • インストール後、Ubuntu用のユーザ名、パスワードを聞かれるので入力

Ubuntuのターミナルのログ

Installing, this may take a few minutes…
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: xxxx    ←★ユーザ名入力
New password:xxxxxxxx                 ←★パスワード入力
Retype new password:xxxxxxxx      ←★パスワード再入力
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)

WSLのディストリビューションのバージョンを確認

WSLのディストリビューションのバージョン確認を行う。

コマンド

wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         1

UbuntuのVERSIONが 1 となっているので、 2 にアップグレードする

コマンド

wsl --set-version Ubuntu 2

再度確認し、VERSIONが 2 に変わっていればOK。

Docker Desktop for Windowsのインストール

Docker Hubの公式HPからダウンロードする

Docker Hub

  • 「Get Docker Desktop for Windows (Edge)」を選択してダウンロード
  • ダウンロード後、Dockerのインストーラ実行
  • 再起動(が必要なはず)
  • デスクトップアイコンから、Docker Desktopを実行

Docker Desktopのバージョン確認

コマンドプロンプトから下記コマンドを実行。

wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

VERSIONが 2 になっていればOK。  

Docker Desktopの設定

下記の設定を行う。 * Docker Desktop→Settings→General→「Use the WSL 2 based engine」をチェック * Docker Desktop→Settings→Resource→WSL INTEGRATION→UbuntuをON * Apply &  Restartボタンをクリック

Dockerの動作確認

wslのターミナルから、適当なコンテナが動くことを確認する。 ここでは hello-worldコンテナを起動させる

  • wsl.exeを実行し、ターミナルを表示させる
  • コマンド docker run hello-world を実行
  • Hello from Docker! がターミナルに表示されればOK
xxxx@XXXXX:/mnt/c/WINDOWS/system32$ 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 .exedaemon.
 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/

 以上。

参考記事

Windows 10 Home 対応の Docker Desktop for Windows を一足早く試してみました|TechRacho(テックラッチョ)〜エンジニアの「?」を「!」に〜|BPS株式会社

【WSL入門】第1回 Windows 10標準Linux環境WSLを始めよう:ITの教室 - @IT

Docker Desktop を WSL2 で使う (Windows 10) | エンジニアの何でもメモ帳