天天看點

CentOS7 Docker容器無法ping通主控端ip問題解決記錄

Docker服務部署啟動容器發現docker容器内通路主控端IP不通,于是進入容器内ping主控端IP,發現無法ping通,容器IP為172.17.0.2,于是繼續ping172.17.0.1也不通,ping docker0也不通,進過網上查詢相關資料,有其他大佬也遇到這個坑,這裡記錄一下。

問題

環境

作業系統:centos 7.9

核心版本:3.10.0-1127.19.1.el7.x86_64

Docker版本:19.03

現象

Docker ping容器内host網絡沒有問題,但是通路ip不同,通路docker0網卡不通

原因

docker 加載核心的bridge.ko 驅動異常,導緻docker0 網卡無法轉發資料包,也就是系統核心的網橋子產品bridge.ko 加載失敗導緻

解決辦法

更新作業系統核心,重新安裝docker

實施

centos7 更新作業系統核心

1、檢視作業系統核心版本

$ uname -r
3.10.0-1127.19.1.el7.x86_64

$ uname -a 
Linux VM-0-16-centos 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.9.2009 (Core)
Release:	7.9.2009
Codename:	Core 
           

2、核心更新(離線)

下載下傳鏡像

centos官方鏡像位址:https://elrepo.org/linux/kernel/el7/x86_64/RPMS/ ,選擇合适版本下載下傳。lt是長期支援版本,ml是最新釋出的穩定版本,我這裡選擇的是lt版本

  • kernel-lt-5.4.92-1.el7.elrepo.x86_64.rpm
  • kernel-lt-devel-5.4.92-1.el7.elrepo.x86_64.rpm

安裝鏡像

$ yum install -y kernel-lt-devel-5.4.92-1.el7.elrepo.x86_64.rpm
$ yum install -y kernel-lt-5.4.92-1.el7.elrepo.x86_64.rpm
           

檢視核心版本順序

# 如下所示,5.4.92的位置在0
$ awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (5.4.92-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux 7 Rescue 1f37b745f7cc48a0a6f2eccdf2406089 (3.10.0-1160.11.1.el7.x86_64)
CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)
           

修改核心啟動順序

如果想生效最新的核心,還需要修改核心的啟動順序為0:

vim /etc/default/grub,找到GRUB_DEFAULT=saved,将saved修改為核心位置,此處為0,則改為GRUB_DEFAULT=0

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_TERMINAL_OUTPUT="serial console"
GRUB_CMDLINE_LINUX="crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable"
GRUB_DISABLE_RECOVERY="true"
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"
           

重新生成grup配置檔案

$ grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.92-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.92-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.11.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.19.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.19.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1f37b745f7cc48a0a6f2eccdf2406089
Found initrd image: /boot/initramfs-0-rescue-1f37b745f7cc48a0a6f2eccdf2406089.img
           

重新開機并檢視核心

$ reboot
Connection closing...Socket close.
Connection closed by foreign host.

$ uname -r
5.4.92-1.el7.elrepo.x86_64
           

做完上述動作,解除安裝重新安裝docker即可

參考:centos7中docker網絡docker0與容器間網絡不通的坑

繼續閱讀