Ubuntu系統(tǒng)下Docker啟動(dòng)失敗(iptables/nf_tables)的問(wèn)題排查與修復(fù)方法
引言
在 Ubuntu 系統(tǒng)中安裝 Docker 后,有部分用戶(hù)在啟動(dòng) Docker 服務(wù)時(shí)遇到如下報(bào)錯(cuò):
Failed to start Docker Application Container Engine. failed to create NAT chain DOCKER: iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Invalid argument
本文將詳細(xì)解釋該問(wèn)題的原因,并提供完整的修復(fù)方案。
問(wèn)題現(xiàn)象
使用以下命令啟動(dòng) Docker:
sudo systemctl start docker
執(zhí)行后,使用以下命令查看docker運(yùn)行情況
sudo systemctl status docker
發(fā)現(xiàn)狀態(tài)為 failed,

使用以下命令查看詳細(xì)錯(cuò)誤日志
sudo journalctl -u docker.service --no-pager --since "10 minutes ago"

伴隨日志提示:
failed to create NAT chain DOCKER: iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Invalid argument
這是 Docker 在使用默認(rèn) iptables-nft 后端時(shí),與內(nèi)核的 nf_tables 實(shí)現(xiàn)存在兼容性問(wèn)題,無(wú)法創(chuàng)建 NAT 表中用于容器網(wǎng)絡(luò)的 DOCKER chain。
原因分析
Ubuntu 從 20.04 起,iptables 默認(rèn)使用 nf_tables 模式,而 Docker 更穩(wěn)定地支持 iptables-legacy 模式。
這就導(dǎo)致 Docker 啟動(dòng)時(shí)無(wú)法正確配置網(wǎng)絡(luò)橋接規(guī)則,從而守護(hù)進(jìn)程失敗退出。
解決方案:切換為 iptables-legacy 模式
1. 確保系統(tǒng)已安裝 iptables(非 nft 工具包)
sudo apt install iptables
2. 執(zhí)行切換命令(無(wú)需單獨(dú)安裝 iptables-legacy 包)
sudo update-alternatives --config iptables
系統(tǒng)會(huì)提示你可選項(xiàng),例如:

選擇帶有 iptables-legacy 的序號(hào)(如 1),然后回車(chē)。
同理,切換 IPv6:
sudo update-alternatives --config ip6tables

3. 若缺少 iptables-legacy 可用項(xiàng),可軟鏈接模擬:
sudo ln -sf /usr/sbin/iptables /usr/sbin/iptables-legacy sudo ln -sf /usr/sbin/ip6tables /usr/sbin/ip6tables-legacy sudo update-alternatives --install /usr/sbin/iptables iptables /usr/sbin/iptables-legacy 100 sudo update-alternatives --install /usr/sbin/ip6tables ip6tables /usr/sbin/ip6tables-legacy 100
然后再次運(yùn)行 --config 命令進(jìn)行選擇。
4. 重啟 Docker 服務(wù)
sudo systemctl daemon-reexec sudo systemctl restart docker
5. 驗(yàn)證是否恢復(fù)正常
docker info docker run hello-world
如無(wú)報(bào)錯(cuò)即修復(fù)成功。
到此這篇關(guān)于Ubuntu系統(tǒng)下Docker啟動(dòng)失敗(iptables/nf_tables)問(wèn)題排查與修復(fù)方法的文章就介紹到這了,更多相關(guān)Ubuntu Docker啟動(dòng)失敗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
CentOS 7.* 更換國(guó)內(nèi)鏡像源完整指南
對(duì)于國(guó)內(nèi)的CentOS用戶(hù)來(lái)說(shuō),使用官方源進(jìn)行軟件安裝和系統(tǒng)更新往往會(huì)遇到速度慢、連接不穩(wěn)定等問(wèn)題,本文將詳細(xì)介紹如何為CentOS 7.*系統(tǒng)更換國(guó)內(nèi)鏡像源,大幅提升軟件包下載速度,需要的朋友可以參考下2025-08-08
Linux遠(yuǎn)程訪(fǎng)問(wèn)及控制方式
SSH(Secure Shell)是一種協(xié)議,用于安全地通過(guò)不安全的網(wǎng)絡(luò)進(jìn)行遠(yuǎn)程登錄和其他網(wǎng)絡(luò)服務(wù),OpenSSH是SSH協(xié)議的一種開(kāi)源實(shí)現(xiàn),它支持?jǐn)?shù)據(jù)加密,能有效防止信息泄露,適用于多種操作系統(tǒng),SSH配置包括服務(wù)端和客戶(hù)端,可以通過(guò)密碼或密鑰對(duì)驗(yàn)證方式進(jìn)行身份驗(yàn)證2024-09-09
6種查看Linux進(jìn)程占用端口號(hào)的方法詳解
對(duì)于 Linux 系統(tǒng)管理員來(lái)說(shuō),清楚某個(gè)服務(wù)是否正確地綁定或監(jiān)聽(tīng)某個(gè)端口,是至關(guān)重要的,本文為大家分享6種查看Linux進(jìn)程占用端口號(hào)的方法分別是:ss,netstat,lsof fuser,nmap,systemctl2018-10-10
apache虛擬主機(jī)中設(shè)置泛域名解析的方法
apache虛擬主機(jī)中設(shè)置泛域名解析,主要是用到ServerAlias 的配置,供大家學(xué)習(xí)參考2013-02-02
在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的方法
這篇文章主要給大家介紹了關(guān)于如何在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Linux具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

