解决WSL2的ubuntu20.04中安装docker出现无法连接的问题(Cannot connect to the Docker daemon)

wsl2的ubuntu20.04系统安装docker可以参考官网教程操作,我个人喜欢参考其中的离线安装方式:Install from a package。只需要按照官网一步步操作即可,跟普通的ubuntu20.04的安装是一样的步骤。

在安装完以后,发现一旦使用docker相关命令会出现下述问题:

bash 复制代码
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

说明docker没有正常启动。这个原因主要是wsl2造成的。

解决方法很简单,首先输入下述命令:

bash 复制代码
sudo update-alternatives --config iptables

然后会输出下述信息:

bash 复制代码
  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即可。

最后重新启动docker:

bash 复制代码
sudo service docker start

这样问题就解决了。

相关推荐
鸠摩智首席音效师3 小时前
linux 系统中 Shutting Down, Restarting, Halting 有什么区别 ?
linux·运维·服务器
CIb0la3 小时前
Linux 将继续不支持 HDMI 2.1 实现
linux·运维·服务器
hhhjjjj3 小时前
docker安装postgreSQL
docker·postgresql·容器
吕了了4 小时前
85 微PE吕了了修改版--更新!
运维·windows·电脑·系统
鹿鸣天涯4 小时前
Kali Linux 2025.4 发布:桌面环境增强,新增 3 款安全工具
linux·运维·安全
学习&笔记5 小时前
MTK(系统篇)user版本无法使用setenforce 0命令关闭selinux权限
linux·运维·服务器
Bdygsl5 小时前
Linux(8)—— 进程优先级与环境变量
linux·运维·服务器
吕了了5 小时前
87 Windows 系统安装的本质是什么?
运维·windows·电脑·系统
阿里巴巴P8资深技术专家6 小时前
docker容器启动报错
运维·docker·容器
杨云龙UP6 小时前
MySQL 8.0.x InnoDB 写入链路优化:Redo Log 与 Buffer Pool 扩容与缓冲区调优实战记录-20251029
linux·运维·数据库·sql·mysql