LoginSignup
1
1

More than 3 years have passed since last update.

WSLでdockerの環境構築

Last updated at Posted at 2020-08-27

はじめに

dockerをwslから動かそうと試み、丸一日溶けたので記録しておきます。

また、わざと"WSL"と書きましたが、前提条件は以下です。

  • Windows OS ビルド 19041以上
  • WSL2であること
  • 管理者権限でコマンドプロンプトを立ち上げていること
  • docker のバージョンが17.12.1であること
  • docker hub にアカウント登録していること

上記の通り、実際はWSL2でないといけないようです。
ですが、WSLで丸1日時間を費やしてしまいましたし、ほかにもWSLで頑張ってググり、困っている方がいるかと思うので、わざとタイトルはこうしました。

ちなみに、WSL1でも最後のhello-worldまでは成功します。
そのあと、apt-getを使ってパッケージを入れようとすると全く動かなくなります。
そのため、あとの作業のためにWSL2にしておくことを推奨します。

step1: windowsのアップデート

以下のページからアップデートできます。
[https://www.microsoft.com/ja-jp/software-download/windows10:embed:cite]

step2: WSL2への変更

以下の記事を参考に進めました。
[https://dev.classmethod.jp/articles/how-to-setup-wsl2/:embed:cite]
ちなみに、私はすでにWSLでUbuntuが入っていたため、新しくUbuntuをインストールすることなく以下を実行して、すでにあるUbuntuをWSL2で動作させるようにしました。

wsl --set-version Ubuntu 2

step3: dockerのインストール

wslを立ち上げ、以下を実行します。

sudo apt install docker.io=17.12.1-0ubuntu1

さらに、ユーザーのグループにdockerをセカンダリグループとして追加します。

sudo usermod -aG docker $USER

docker daemonの起動

以下を実行します。

sudo cgroupfs-mount && sudo service docker start

以下のコマンドで、起動していることを確認しましょう

sudo service docker status

以下のように表示されていればOKです。

*docker running

以下を実行して、うまく起動しているかを確認しましょう。

sudo docker run hello-world

以下のように表示されていればOKです。

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