wsl中是不能用systemctl来进行启动服务的,只能用service
但是service启动失败
看了下日志
time="2022-07-27T21:23:46.131907580+08:00" level=info msg="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))
说的是iptables的问题,这个之前在github中提到过#1105
解决方法如下:
首先将iptables用iptables-legacy替换
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
然后,开启ipv4的包转发功能
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
最后在powershell中重启wsl
wsl --shutdown
这样再打开wsl之后就能顺利启动了