wsl中迁移ubuntu24.04后docker后无法启动的问题

wsl中迁移ubuntu24.04后docker后无法启动的问题

发生原因

我将外网wsl2中的Ubuntu24.04迁移到内网(无网络)电脑中,发现原本安装的docker无法启动,

在使用 apt-get install docker-ce docker-ce-cli containerd.io重新安装后依然不行

NOTE:迁移后软件会失去注册信息,运行会提示命令未注册,所以需要重新安装。其实系统中已经包含了相关安装包,所以不会联网下载

原因

查看Docker的日志vim /var/log/docker.log显示如下的错误

shell 复制代码
time="2025-04-09T10:29:59.904691194+08:00" level=info msg="Loading containers: start."
time="2025-04-09T10:30:00.055889722+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
time="2025-04-09T10:30:00.056182637+08:00" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2025-04-09T10:30:00.056254606+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to register "bridge" driver: failed to add jump rules to ipv4 NAT table: failed to append jump rules to nat-PREROUTING:  (iptables failed: iptables --wait -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER: Warning: Extension addrtype revision 0 not supported, missing kernel module?
iptables v1.8.10 (nf_tables):  CHAIN_ADD failed (No such file or directory): chain PREROUTING
 (exit status 4))

原因是由于迁移后ubuntu系统使用了iptables-nft,而WSL2不支持导致的。

修复

修改为iptables-legacy即可

shell 复制代码
 root@DESKTOP-5DTRJV0:/home/friday/apt-offline# 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
root@DESKTOP-5DTRJV0:/home/friday/apt-offline# service docker start
 * Starting Docker: docker                                               [ OK ]                                                                                                                                              
root@DESKTOP-5DTRJV0:/home/friday/apt-offline# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
相关推荐
小马同学-2 小时前
nerdctl实战:Docker风格的Containerd操作利器
docker·容器·containerd
九皇叔叔3 小时前
Kubernetes 命令式对象配置详解:使用 YAML 管理 Kubernetes 资源
docker·容器·k8s
CVer儿4 小时前
docker内llama.cpp和TRT-LLM win11本机部署qwen3.8
docker
萤火夜4 小时前
Docker(四) Docker介绍
docker·容器
.冰块.5 小时前
Docker 镜像深度学习:分层 Copy‑on‑Write、Dockerfile 语法、Harbor 私有仓库实操
docker·容器·harbor·镜像·dockerfile·images
szephyr5 小时前
Docker 镜像瘦身实战:从 1.2GB 压到 85MB 的完整过程
docker·容器·部署·多阶段构建·镜像优化
溪语流沙7 小时前
Django + Vue电商项目第001讲:开篇|注册登录加增删改查,那不是电商
redis·python·mysql·docker·typescript·django·vue
一直在努力学习的菜鸟9 小时前
Docker Info 详细解析(Rocky Linux 8.10 / Docker 29.8.1)
docker
AlfredZhao10 小时前
Docker 删除 none 镜像:一次真实的清理记录
docker
bosins19 小时前
WSL2 启动即崩溃?调整超时参数解决 Docker 阻塞问题
linux·docker·wsl