dockerをWindows10 HomeのWSL (Windows Subsystem for Linux)で動かしてみた

ヨメレバCSS
オリジナルCSS

 WSL上でDocker Engineが動くようになっていたっぽいという話

 WindowsのWSLでDockerが動くらしいとの話を見かけたので試してみました。

 やってることはだいたい先の記事にあるだけです。

 結果としてdockerは動いたのですが、ネットワーク周りがだめみたいでdocker-composeは動きませんでした。

スポンサーリンク
GoogleAdSence レクタングル(大)

環境

  • Windows 10 Home
  • Ubuntu 16.04.4  (WSL ストア版)

 また私の環境にはもともとLegasy (Bash On Windows)のUbuntuが入っていて、そちらでもストア版と同じところまでいけました。

Ubuntuを管理者権限で起動する

 dockerを動かすには管理者権限が必要のようです。これが無い場合はサービスが起動しませんでした。

 管理者権限での起動は、スタートメニューの「Ubuntu」を右クリックして「その他 > 管理者として実行」を行います。

dockerをインストール

 apt-getでインストールします。

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install docker.io
$ sudo cgroupfs-mount
$ sudo usermod -aG docker $USER
$ sudo service docker start

dockerのサービスが起動しています。

$ service docker status
 * Docker is running

 hello-worldイメージを実行してみます。

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d
Status: Downloaded newer image for hello-world:latest

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/engine/userguide/

やったぜ。

startでは「OK」と出たのにサービスが起動しないとき

 docker startでは「OK」と出ていても、その後のサービスが起動していないときがありました。

 /var/log/docler.logを見てみると、次のエラーがありました。

Error starting daemon: Error initializing network controller: Error creating default "bridge" network: Failed to Setup IP tables: Unable to enable NAT rule:  (iptables failed: iptables --wait -t nat -I POSTROUTING -s 172.20.0.0/16 ! -o docker0 -j MASQUERADE: iptables: Invalid argument. Run `dmesg' for more information.
 (exit status 1))

demsgには次のようにありました。

dmesg: read kernel buffer failed: Function not implemented

これが割とよく分からなくて、Dockerサービスが起動しないときで調べていたらUbuntuを再起動しろとあったのでOn Windowsだしなといろいろ察してマシン再起動したら治りました。

docker-composeを実行してみる

 次にdocker-comopseを入れてみます。

 こちらは別のパッケージになっているようなのでインストールから。

$ sudo apt-get install docker-compose

 カレントディレクトリに次のようなymlを作ります。とりあえず確認用です。

version: "2"

services:
  app:
    image: hello-world

そして、docker-composeで起動してみます。

$ sudo docker-compose up

 しかし結果は、次のようにエラーとなりました。

Creating network "kagerou_default" with the default driver
ERROR: Failed to Setup IP tables: Unable to enable NAT rule:  (iptables failed: iptables --wait -t nat -I POSTROUTING -s 172.23.0.0/16 ! -o br-81a6d268e728 -j MASQUERADE: iptables: No chain/target/match by that name.
 (exit status 1))

 実行されてるiptablesの小窓には問題ないように思えますが、手動で試してみてもダメっぽい。

 調べてみると同じところで引っかかっている方もいました。

wslでdockerが動く

 それでどうも、WSLはWindowsのカーネルを使っているからネットワーク周りなどでまともに動かないコマンドがあるみたいな話もあって。

Running docker compose on windows ubuntu subsystem


The WSL subsystem runs on a Microsoft kernel and not a Linux kernel.
Thus many Linux networking commands do not work, iptables is one of them.

 今のところ、dockerは動くけどネットワーク周りが動かない(のでdocker-composeが使えない)といった感じです。

 あと一歩感がありますわー

参考:

WSL上でDocker Engineが動くようになっていたっぽいという話

docker is running natively on wsl

スポンサーリンク
GoogleAdSence レクタングル(大)

シェアする

スポンサーリンク
GoogleAdSence レクタングル(大)