Docker无法在WSL2的Ubuntu启动的问题

今天在更新了WSL2上的Ubuntu22.04版本,在安装Docker后无法启动,查看Docker的日志显示如下的错误

INFO[2022-04-22T16:14:55.718999500+08:00] stopping event stream following graceful shutdown  error="" module=libcontainerd namespace=moby
INFO[2022-04-22T16:14:55.719787400+08:00] stopping event stream following graceful shutdown  error="context canceled" module=libcontainerd namespace=plugins.moby
INFO[2022-04-22T16:14:55.719906400+08:00] stopping healthcheck following graceful shutdown  module=libcontainerd
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))

原因是由于新的ubuntu系统使用了iptables-nft,而WSL2不支持导致的。

可以通过以下命令进行修改

sudo update-alternatives --config iptables
There are 2 choices for the alternative iptables (providing /usr/sbin/iptables).

  Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/sbin/iptables-nft      20        auto mode
  1            /usr/sbin/iptables-legacy   10        manual mode
  2            /usr/sbin/iptables-nft      20        manual mode

Press  to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode

修改完成后重启Docker服务即可。

你可能感兴趣的:(系统运维,Docker,docker,wsl2)