一、无法连接到docker官方源
报错如下:
root@————————————————:~# apt update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu jammy InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-backports InRelease
Hit:4 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-security InRelease
Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease
Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease
Ign:5 https://download.docker.com/linux/ubuntu jammy InRelease
Err:5 https://download.docker.com/linux/ubuntu jammy InRelease
Could not handshake: Error in the pull function. [IP: 3.170.229.111 443]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/InRelease Could not handshake: Error in the pull function. [IP: 3.170.229.111 443]
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@iZuf6dcmbpbqrs8t33kcyhZ:~# sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Unable to locate package docker-buildx-plugin
E: Unable to locate package docker-compose-plugin
问题是由于 访问 Docker 官方源失败 导致的安装包无法获取。报错关键是这一句:
Could not handshake: Error in the pull function. [IP: 3.170.229.111 443]
这说明你的服务器当前网络环境(很可能是在国内)无法成功与 download.docker.com 建立 TLS 握手,属于网络连接问题(通常是被墙)。
解决方案:使用 Docker 国内镜像源(中科大 / 阿里云等)
我们将切换到 国内加速源 来完成 Docker 安装。
步骤一:清理错误的 Docker 源
执行以下命令删除失效源:
sudo rm /etc/apt/sources.list.d/docker.list
sudo apt update
步骤二:添加国内源(中科大源)
创建密钥:
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
写入源配置(适配 jammy):
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
步骤三:更新并安装 Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
可选步骤:配置镜像加速器(用于 Docker 拉取镜像加速)
创建或编辑文件 /etc/docker/daemon.json:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json > /dev/null <<EOF
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
重启 Docker:
sudo systemctl daemon-reexec
sudo systemctl restart docker
完成以上步骤后,应该可以顺利安装并运行 Docker 以及 Docker Compose。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
