在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 系统是非常关键的信息。

相关推荐
---学无止境---7 小时前
Linux中驱动程序通过fasync异步通知应用程序的实现
linux
cccyi77 小时前
Linux 进程间通信机制详解
linux·进程通信
北京迅为7 小时前
【北京迅为】iTOP-4412精英版使用手册-第三十五章 WEB控制LED
linux·嵌入式硬件·嵌入式·4412
让我们一起加油好吗8 小时前
【C++】封装红黑树模拟实现 set 和 map
linux·c++·set·map·红黑树
Gss7778 小时前
Docker 公有仓库使用、Docker 私有仓库(Registry)使用总结
docker·容器
暴富奥利奥8 小时前
完成docker方式的ros环境配置
linux·学习·docker·容器
秃头菜狗8 小时前
十四、运行经典案例 wordcount
大数据·linux·hadoop
望获linux9 小时前
【实时Linux实战系列】实时系统的可观测性:Prometheus 与 Grafana 集成
大数据·linux·服务器·开发语言·网络·操作系统
hweiyu009 小时前
Linux 命令:mount
linux·运维·服务器
zhmy_0069 小时前
linux 多服务器下目录数据文件实时同步
linux·文件实时同步