在安装Docker后无法启动,查看Docker的日志vim /var/log/docker.log
显示如下的错误
time="2022-12-27T00:36:54.741331300+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
time="2022-12-27T00:36:54.741621100+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
time="2022-12-27T00:36:54.741646800+08:00" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2022-12-27T00:36:55.742640100+08:00" level=warning msg="grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}. Err :connection error: desc = \"transport: Error while dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout\". Reconnecting..." 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))
原因是由于新的ubuntu系统使用了iptables-nft,而WSL2不支持导致的。
可以通过以下命令进行修改
mango@wanzhouyi:/var/log$ 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 <enter> 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
mango@wanzhouyi:/var/log$ sudo service docker start
* Starting Docker: docker [ OK ]
mango@wanzhouyi:/var/log$ sudo service docker status
* Docker is running
修改完成后重启Docker服务即可
标签:iptables,sbin,log,22.04,usr,ubuntu,var,docker From: https://www.cnblogs.com/zhouXX/p/17007216.html