萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> MySQL 教學

Docker「Unable to find image locally」阿里云镜像源修复全记录

錯誤現象

Unable to find image 'busybox' locally
Pulling repository registry
Could not reach any registry endpoint

環境:阿里雲 VPS,鏡像市場「Docker 運行環境(Ubuntu 64 位)」,Docker 版本 1.2.0(極舊)。

根因分析

  1. Docker 1.2.0 過舊,預設 Registry API 版本不兼容現代 Docker Hub/Registry v2。
  2. 阿里雲預設 /etc/apt/sources.list 使用官方 Ubuntu 源,國內下載極慢且部分 404,導致 apt-get install docker.io 升級失敗。

三步驟徹底修復

步驟 1:替換為阿里雲 Ubuntu 鏡像源

cat > /etc/apt/sources.list <<'EOF'
deb https://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src https://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
EOF

步驟 2:清理快取並更新索引

apt-get clean && apt-get update

步驟 3:安裝/升級 Docker Engine

apt-get install -y docker.io

安裝完成後版本將升級至 1.12+(Ubuntu 14.04 預設倉庫版本),支援 Registry v2,拉取鏡像即可正常。

驗證

docker pull busybox
docker run --rm busybox echo "Hello from fixed Docker!"

進階建議:直接安裝 Docker 官方最新版

若需更穩定、更新的版本(含 BuildKit、Compose V2),建議執行官方安裝腳本:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# 國內鏡像加速下載

並配置 /etc/docker/daemon.json 加速器:

{
  "registry-mirrors": ["https://.mirror.aliyuncs.com"]
}
copyright © 萬盛學電腦網 all rights reserved