Ubuntu系統(tǒng)下Docker啟動失敗(iptables/nf_tables)的問題排查與修復方法
引言
在 Ubuntu 系統(tǒng)中安裝 Docker 后,有部分用戶在啟動 Docker 服務時遇到如下報錯:
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
本文將詳細解釋該問題的原因,并提供完整的修復方案。
問題現(xiàn)象
使用以下命令啟動 Docker:
sudo systemctl start docker
執(zhí)行后,使用以下命令查看docker運行情況
sudo systemctl status docker
發(fā)現(xiàn)狀態(tài)為 failed,

使用以下命令查看詳細錯誤日志
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 在使用默認 iptables-nft 后端時,與內(nèi)核的 nf_tables 實現(xiàn)存在兼容性問題,無法創(chuàng)建 NAT 表中用于容器網(wǎng)絡的 DOCKER chain。
原因分析
Ubuntu 從 20.04 起,iptables 默認使用 nf_tables 模式,而 Docker 更穩(wěn)定地支持 iptables-legacy 模式。
這就導致 Docker 啟動時無法正確配置網(wǎng)絡橋接規(guī)則,從而守護進程失敗退出。
解決方案:切換為 iptables-legacy 模式
1. 確保系統(tǒng)已安裝 iptables(非 nft 工具包)
sudo apt install iptables
2. 執(zhí)行切換命令(無需單獨安裝 iptables-legacy 包)
sudo update-alternatives --config iptables
系統(tǒng)會提示你可選項,例如:

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

3. 若缺少 iptables-legacy 可用項,可軟鏈接模擬:
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
然后再次運行 --config 命令進行選擇。
4. 重啟 Docker 服務
sudo systemctl daemon-reexec sudo systemctl restart docker
5. 驗證是否恢復正常
docker info docker run hello-world
如無報錯即修復成功。
到此這篇關(guān)于Ubuntu系統(tǒng)下Docker啟動失敗(iptables/nf_tables)問題排查與修復方法的文章就介紹到這了,更多相關(guān)Ubuntu Docker啟動失敗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在Linux系統(tǒng)中查看目錄大小的方法小結(jié)
在 Linux 系統(tǒng)中,管理文件和目錄的磁盤空間使用情況是日常維護的一部分,特別是在數(shù)據(jù)密集型的應用場景中,了解各個目錄和文件的大小至關(guān)重要,du(disk usage)命令是一個強大的工具,可以幫助我們獲取目錄及其子目錄的大小信息,需要的朋友可以參考下2024-11-11
LuManager圖文安裝使用教程和創(chuàng)建MysqL快速建站基本教程
這篇文章主要介紹了LuManager圖文安裝使用教程和創(chuàng)建MysqL快速建站基本教程,需要的朋友可以參考下2016-04-04
分享apache http服務器設(shè)置虛擬主機的方法
對于多個域名綁定到一臺服務器上,需要進行虛擬主機(virtual host)相關(guān)的設(shè)置,假設(shè)我要設(shè)置fuwu.jb51.net到一臺服務器上,應該如何做虛擬主機的設(shè)置呢?2011-08-08
Ubuntu基礎(chǔ)設(shè)定:openssh-server的安裝和使用介紹
今天小編就為大家分享一篇關(guān)于Ubuntu基礎(chǔ)設(shè)定:openssh-server的安裝和使用介紹,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01
CentOS7下實現(xiàn)終端輸入中文設(shè)置詳解
這篇文章主要給大家介紹了關(guān)于CentOS7下實現(xiàn)終端輸入中文設(shè)置的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用CentOS7系統(tǒng)具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-07-07

