WSL1下运行docker出现的“Cannot connect to the Docker daemon at u

https://www.jianshu.com/p/62510e360620

service docker start

ps -ef | grep docker

docker images

运行环境
OS:Win10 1909(内部版本18363.481)
WSL:1
Linux Distribution:Ubuntu 20.04
docker:20.10.6

错误信息
查看本地docker镜像时提示:

root@localhost:~# docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解决办法
首先确认是否启动了docker

root@localhost:~# ps -ef | grep docker
root        39    10  0 14:17 pts/0    00:00:00 grep --color=auto docker

如上图所示,就是docker没有启动,使用如下命令启动docker后:

root@localhost:~# service docker start
 * Starting Docker: docker                                         [OK]

重新检查docker进程是否存在:

root@localhost:~# ps -ef | grep docker
root        90     9  0 14:21 ?        00:00:00 /usr/bin/dockerd -p /var/run/docker.pid
root       105    90  0 14:21 ?        00:00:00 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
root       247    10  0 14:22 pts/0    00:00:00 grep --color=auto docker

如上信息表示docker已成功启动。

如果docker未能启动成功,查看docker启动日志/var/log/docker.log(Ubuntu),如果日志末尾是如下错误信息:

time="2021-05-31T20:44:03.396093900+08:00" level=warning msg="Running iptables --wait -t nat -L -n failed with message: `iptables v1.8.4 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)\nPerhaps iptables or your kernel needs to be upgraded.`, error: exit status 3"
time="2021-05-31T20:44:03.632996500+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
time="2021-05-31T20:44:03.633028700+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
time="2021-05-31T20:44:03.633035700+08:00" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2021-05-31T20:44:04.633797400+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: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.8.4 (legacy): 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)

则需要将WSL1升级为WSL2,升级更新操作可以参考在Win10中安装Ubuntu中的“更新到WSL 2”章节。

文档更新时间: 2024-04-10 09:26   作者:admin