You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu20.04.5无法安装指定版本docker.io的排查与解决求助

问题排查与解决:Ubuntu 20.04无法安装指定版本docker.io并出现仓库索引错误

一、问题现象

1. Docker指定版本安装失败

执行命令尝试安装特定版本docker.io时提示版本不存在:

root@Ubuntu:/home/ravi/# apt-get install -y --allow-downgrades --allow-change-held-packages --allow-unauthenticated --ignore-hold docker.io=20.10.12-0ubuntu2~20.04.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Version '20.10.12-0ubuntu2~20.04.1' for 'docker.io' was not found

2. APT仓库更新索引失败

执行apt-get update时出现DNS解析错误:

+ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg
+ apt-key add -
OK
+ echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main'
+ mkdir -p /etc/apt/apt.conf.d
+ echo 'APT::Acquire::Retries "3";'
+ apt-get update
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease                                        
Get:1 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [8,993 B]                       
Err:3 http://in.archive.ubuntu.com/ubuntu focal InRelease                                                                                                 
  Temporary failure resolving 'in.archive.ubuntu.com'
Hit:4 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Fetched 8,993 B in 21s (432 B/s)
Reading package lists... Done
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'in.archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

系统版本

root@Ubuntu:~# lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:    20.04
Codename:   focal

二、先解决APT仓库索引解析失败问题

DNS解析失败会导致无法获取最新仓库索引,是找不到Docker版本的直接原因之一:

  • 检查DNS配置:查看当前DNS服务器
    cat /etc/resolv.conf
    
  • 临时替换DNS:编辑/etc/resolv.conf添加可靠公共DNS,再重启网络服务:
    echo "nameserver 8.8.8.8" >> /etc/resolv.conf
    systemctl restart systemd-resolved
    
  • 更换Ubuntu镜像源:国内访问官方源不稳定时,替换为国内镜像(如阿里云):
    1. 备份原源文件:cp /etc/apt/sources.list /etc/apt/sources.list.bak
    2. 替换源内容:
      cat > /etc/apt/sources.list << EOF
      deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
      EOF
      
    3. 更新仓库:apt-get update

三、Docker指定版本找不到的原因

  • Ubuntu官方仓库会定期移除旧版本软件包,尤其是当有安全补丁或新版本替代时,20.10.12版本的docker.io可能已被从focal仓库下架。
  • 之前成功安装依赖本地缓存的旧索引,缓存过期或更新失败后,无法再找到该版本。

四、调试方法

  • 查看仓库中可用的docker.io版本:列出当前仓库所有可安装版本
    apt-cache madison docker.io
    
  • 检查本地APT缓存状态:查看本地缓存版本与仓库可用版本
    apt-cache policy docker.io
    
  • 验证仓库连通性:测试Ubuntu仓库是否可正常访问
    curl -I http://mirrors.aliyun.com/ubuntu/dists/focal/universe/binary-amd64/Packages.gz
    

五、解决办法

方法1:安装仓库中可用的同系列兼容版本

用apt-cache madison docker.io找到20.10.x系列的最新可用版本,例如假设为20.10.25-0ubuntu1~20.04.1,执行安装:

apt-get install -y docker.io=20.10.25-0ubuntu1~20.04.1

方法2:从Docker官方源安装指定版本

Ubuntu自带的docker.io版本库有限,改用Docker官方源可获取更全的历史版本:

  1. 卸载现有Docker相关包(如果存在):
    apt-get purge -y docker.io docker-compose
    apt-get autoremove -y
    
  2. 添加Docker官方GPG密钥:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  3. 添加官方源:
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  4. 更新仓库:apt-get update
  5. 查看官方源中20.10.12版本的完整包名:
    apt-cache madison docker-ce
    
  6. 安装指定版本:
    apt-get install -y docker-ce=5:20.10.12~3-0~ubuntu-focal docker-ce-cli=5:20.10.12~3-0~ubuntu-focal containerd.io
    

方法3:手动下载DEB包安装

  1. 在Ubuntu官方包归档中搜索docker.io_20.10.12-0ubuntu2~20.04.1_amd64.deb包
  2. 下载后执行安装:
    dpkg -i docker.io_20.10.12-0ubuntu2~20.04.1_amd64.deb
    
  3. 修复依赖问题(如果有):
    apt-get install -f
    

六、替代方案

  • 使用Docker官方提供的docker-ce替代Ubuntu自带的docker.io,版本库更全,更新更及时。
  • 改用Podman作为容器运行时替代工具,无需守护进程,兼容Docker命令。

内容的提问来源于stack exchange,提问作者myquest5 sh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 01:47:12