WSL で Docker 起動できない問題: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

公式サイトの説明通り WSL2:Ubuntu22Docker インストールして

sudo service docker start
docker ps

しても

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

と表示されて起動できていない!

dockerのログを確認する

とりあえずログを確認・・・

sudo cat /var/log/docker.log
~~ 中略 ~~
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 周りでエラーが発生したご様子。
RULE_APPEND failed (No such file or directory) が出ていますね。

iptables設定の変更

参考サイトにあるとおりの対応で無事動作させることができました!

# iptablesの設定を変更
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

# docker サービスの再起動
sudo service docker stop
sudo service docker start

参考サイト

【WSL2】DockerでCannot connect to the Docker daemon…と表示される問題の対処 - ReMIXのブログ
https://remix-yh.net/2281/

Subscribe to 猫好きが猫以外のことも書く

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe