LoginSignup
8
9

More than 3 years have passed since last update.

WSLでDockerが動かないときに試したこと

Last updated at Posted at 2019-10-05

はじめに

古いバージョンのDockerを入れてみたり、インストール方法を変えてみたり、Ubuntuのバージョンを変えてみたりしてもダメだったときに試して動くようになった方法を書いておきます。
この方法を試したからと言って必ず動くとは限りませんが、少しでも誰かの助けになればと思います。

環境

Windows10 Pro, version 1809
Ubuntu 16.04 LTS
Ubuntu 18.04 LTS

Docker version 18.09.7

動かない状況

まずは
どうしても Docker on Ubuntu 18.04 on WSL したかった - Qiita
を参考にしてDockerをインストールします。

$ sudo service docker start
 * Starting Docker: docker                                     [ OK ]

と出ているのに

$ sudo service docker status
 * Docker is not running

動かない。

試したこと① -エラーメッセージを見る-

まずは、何が原因で落ちているのかエラーメッセージを見ます。
以下の方法でエラーメッセージを見ることができます。

・ログファイルを見る
Dockerデーモンのログファイルは /var/log/docker.log とか /var/log/upstart/docker.log あたりにあるようです。

$ cat /var/log/docker.log

・直接Dockerデーモンを動かす
sudo service docker startしてからcat /var/log/docker.logというのは地味に面倒なのでこちらがおすすめです。

$ sudo dockerd

エラーメッセージ

自分の場合は、どのバージョンを入れても毎回こんなエラーを吐いて落ちていました。

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.0.0.0/16 ! -o docker0 -j MASQUERADE: iptables: Invalid argument. Run `dmesg' for more information.
 (exit status 1))

どうやらiptablesで失敗しているようです。
WSL1ではiptablesに対応していないので当然のようです。

cgroupfsがどうの…とかのエラーなら
sudo cgroupfs-mountとかsudo usermod -aG docker $USERあたりをやればいいです。

試したこと② -iptablesを無効にする-

対応していないのだから無効にすればいいのです。
https://docs.docker.com/network/iptables/#prevent-docker-from-manipulating-iptables
↑に書いてあるように、コンフィグファイルでiptablesをfalseに設定します。
※上のページではコンフィグファイルのパスが間違っています
 ❌/etc/docker.daemon.json ⭕️/etc/docker/daemon.json
 修正されていました。

/etc/docker/daemon.json
{
        "iptables": false
}

動いた

/var/log/docker.log
INFO[2019-10-05T22:47:43.434054400+09:00] Docker daemon                                 commit=2d0083d graphdriver(s)=overlay2 version=18.09.7
INFO[2019-10-05T22:47:43.434600100+09:00] Daemon has completed initialization
INFO[2019-10-05T22:47:43.445091100+09:00] API listen on /var/run/docker.sock
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
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/get-started/

おしまい

https://docs.docker.com/network/iptables/#prevent-docker-from-manipulating-iptables
に書いてありますが、iptablesを無効にしてしまうと何かよくない影響が出る可能性はあるようです。
ただ、全く動かないよりはいいと思います。

WSL2を使えばこんなことで悩む必要はなくなるので、早く正式リリースしてほしいです。

8
9
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
8
9