0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2にupgradeしてついでにDockerをいれる

Last updated at Posted at 2020-07-18

前回のインストール時の2020/7/4時点だと、デフォルトでインストール
されるのがWSL1だったが、WSL2が正式リリースになっていたのでWSL2を入れる。

まずはWindows Update

現時点でWindows Updateに来ていないので手動で入れる

割と時間が掛かるので気長に待つ。
ついでにWSL2のカーネルも入れておく

仮想化のセットアップ

ここはPowerShellで行う。
PowerShellを 管理者権限で実行 して下記コマンドを実行

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

WSL2へupgrade

ここもPowerShellで行う。
まずは現状確認。

PS C:\WINDOWS\system32> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         1

で、デフォルトをWSL2に変えておく。

wsl --set-default-version 2

既にインストール済みのWSL1のやつがあったらconvertする。

wsl --set-version ubuntu-20.04 2

確認。OK!

  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

Dockerをインストール

ここからはUbuntuで実行。
PGP鍵を入れる。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

aptのrepositoryを追加。

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

インストール。GRUBの設定画面が出るけれど何も選択せずにOKを押す。

sudo apt install -y docker-ce docker-compose

sudoなしでもできるようにグループを追加したうえでdocker daemon起動。

sudo usermod -aG docker $USER
sudo service docker start

docker runで動作チェック

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

ヨシ!

WSL2にしたらコマンドのレスポンスが早くなった気がするし、aptのファイルダウンロード時に200kとかしか出なかったのが3Mくらいは出るようになったのでWSL2化の恩恵はだいぶありそう。(そもそも無線が遅いのは何とかする)

前回のようにdockerをWindowsの管理者権限で実行する必要もなくよいです。

参考

https://qiita.com/TsuyoshiUshio@github/items/947301bd9317610572fc
https://qiita.com/toyotoyo_/items/895c07fb50708b013eba

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?