LoginSignup
0
2

More than 1 year has passed since last update.

【WSL2】UbuntuにDockerをインストールした後、Dockerのログにiptablesが使えないとエラーが出ててDockerそのものが起動してなかったときに対応したこと

Posted at

動作環境

Ubuntu側で確認

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

windows側で確認

 wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Running         2
  Ubuntu-22.04    Running         2

Dockerの公式ドキュメントを見てDockerをインストールしたのにdockerコマンドが実行できない…

WSL2を使って構築したUbuntu上でDocker Desktopを使わずにDockerを実行できるようにしたいと思い
Dockerの公式ドキュメントを見ながらインストールをしてました。

インストールが無事に完了したので、最後に動作確認でdocker runだ!と思って実行したら
想定外の動きに…
Docker demonが動いてないだと?

$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

起動してみる

$ sudo service docker start
 * Starting Docker: docker

起動したか確認

$ sudo service docker status
 * Docker is not running

あれ、動いてない…

環境も問題ないはずなのに、これは何かおかしいなと思ってdockerのログを確認

/var/log/docker.log
time="2023-04-02T12:33:43.987276500+09:00" level=info msg="[core] [Channel #7] Channel Connectivity change to IDLE" module=grpc
failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain:  (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables):  RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1
 (exit status 4))

なんか、iptables関連でエラーになってる!?

原因

新しいiptablesは使えないから、iptables-legacyに切り替えないとエラーになっちゃうとのこと。
これに引っかかってたみたい。

解決手順

上記のIssueに記載されてた以下コマンドをUbuntu上で実行する。

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

もう1度dockerを起動、起動されてるか確認

$ sudo service docker start
 * Starting Docker: docker                                                                  
 
$ sudo service docker status
 * Docker is running
 
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:ffb13da98453e0f04d33a6eee5bb8e46ee50d08ebe17735fc0779d0349e889e9
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/

これで、dockerが起動されるようになった!

参考

0
2
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
2