无法使用新的 Windows 终端在 WSL2 中启动 Docker

Unable to start Docker in WSL2 using new Windows Terminal

我最近安装了 WSL2 并从 Microsoft Store.When 安装了 Ubuntu 我 运行 docker 使用

Sudo 服务docker 启动,我收到以下消息

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我按照这个答案的步骤进行了以下操作

    sudo groupadd docker
sudo usermod -aG docker $(whoami)

但仍然无法启动 docker..检查 Docker 日志时,我可以看到下面的内容

CONNECTING" module=grpc Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.1: can't initialize iptables table nat': Table does not exist (do you need to insmod?) Perhaps iptables or your kernel needs to be upgraded. (exit status 3) `

我已经根据下面的错误尝试了很多步骤

can't initialize iptables table nat': Table does not exist (do you need to insmod?) Perhaps iptables or your kernel needs to be upgraded. (exit status 3) `

但是以管理员身份启动终端 worked.Even 虽然你 运行

sudo service docker start

终端应以管理员身份启动

有一个很棒的指南 here,它提供了一些最新的说明以及使用 WSL 2 和新的 docker 桌面的一些先决条件。

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

来自 https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269