在WSL 2 (Ubuntu 22.04)安装Docker Ce 启动错误解决

查看WSL版本

  • 在 Windows 命令提示符(CMD)或 PowerShell 中,你可以使用以下命令来查看已安装的 WSL 发行版及其版本信息:
plaintext 复制代码
wsl -l -v
shell 复制代码
(base) PS C:\Users\Lenovo> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2

docker启动报错

failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to register "bridge" driver: 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))

解决方法:

在WSL中安装Ubuntu 22.04稳定版后,我按照Docker官方说明继续安装Docker引擎。因为这是WSL,所以运行sudo systemctl start docker不起作用。要启动docker服务,您需要使用sudo /etc/init.d/docker start .

如果使用sudo /etc/init.d/docker status命令检查,你将注意到docker服务没有运行。原因是在启动docker时出现了这个错误。

要解决这个问题,需要将默认iptables更新为 legacy 选项。这样做之后,你应该能够启动docker服务并运行正常的docker命令。

$ 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

选择 1 , 修改选项。

查看windows宿主IP

在 WSL 2 环境下,可以通过查看/etc/resolv.conf文件来获取 Windows 宿主机器的 IP 地址相关信息。这个文件用于配置域名解析,其中包含了从 WSL 2 访问外部网络(包括 Windows 宿主网络)的网关信息。

执行以下命令:

shell 复制代码
cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.30.112.1

这里的172.30.112.1就是 Windows 宿主机器为 WSL 2 提供的网关 IP 地址,这个 IP 地址可用于从 WSL 2 与 Windows 宿主机器进行通信相关的操作。不过,这不是 Windows 宿主机器真正的外部网络 IP 地址,但在 WSL 2 内部用于访问 Windows 系统是非常关键的信息。

相关推荐
致奋斗的我们1 小时前
HAProxy介绍与编译安装
linux·汇编·数据库·mysql·青少年编程·haproxy·openeurler
waves浪游2 小时前
Linux基本指令(上)
linux·运维·服务器
不确定性确定你我2 小时前
`sh` 与 `bash` 的区别详解
linux·bash·运维开发
哥是黑大帅2 小时前
Docker基于Ollama本地部署大语言模型
python·docker·语言模型
9毫米的幻想3 小时前
【Linux系统】—— 冯诺依曼体系结构与操作系统初理解
linux·运维·服务器·c语言·c++
升讯威在线客服系统4 小时前
如何通过 Docker 在没有域名的情况下快速上线客服系统
java·运维·前端·python·docker·容器·.net
leoufung5 小时前
vim 多个关键字高亮插件介绍
linux·编辑器·vim
Karoku0666 小时前
【CI/CD】CI/CD环境搭建流程和持续集成环境配置
运维·ci/cd·docker·容器·kubernetes·prometheus
Nerd Nirvana8 小时前
软考—系统架构设计(案例 | 论文)
linux·系统架构·软件工程·软考·计算机基础
勤奋的凯尔森同学9 小时前
webmin配置终端显示样式,模仿UbuntuDesktop终端
linux·运维·服务器·ubuntu·webmin