当在拉取镜像时报以下错误时,可以通过更换镜像源解决
root@localhost:/etc/docker# docker pull mysql
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
1、修改当前使用的镜像源
打开配置文件,使用 vim 编辑器打开 /etc/docker/daemon.json 文件,若文件不存在则创建该文件:
vim /etc/docker/daemon.json
添加以下内容到文件中,保存并退出
{
"registry-mirrors": [
"https://dockerproxy.net",
"https://docker.rainbond.cc",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.1panel.live",
"https://docker-0.unsee.tech",
"https://registry.dockermirror.com",
"https://docker.imgdb.de",
"https://docker.m.daocloud.io",
"https://hub.firefly.store",
"https://hub.littlediary.cn",
"https://hub.rat.dev",
"https://dhub.kubesre.xyz",
"https://cjie.eu.org",
"https://docker.kejilion.pro",
"https://docker.1panelproxy.com",
"https://docker.hlmirror.com",
"https://hub.fast360.xyz"
]
}
2、执行以下命令,重新加载 Docker 配置文件
# 重新加载 systemd 的配置文件,当修改了 systemd 服务单元文件后使用此命令,让 systemd 识别新的配置
sudo systemctl daemon-reload
# 重新加载 Docker 服务的配置文件,在修改了 Docker 配置文件(如 /etc/docker/daemon.json)后,使用此命令可应用新配置,且不中断正在运行的容器
sudo systemctl reload docker
# 停止并重新启动 Docker 服务,当对 Docker 进行重大更改(如升级版本)或需要完全重置服务状态时使用此命令,会导致所有正在运行的容器停止
# sudo systemctl restart docker
3、执行以下命令,验证镜像源是否已生效
root@localhost:/etc/docker# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
f1a9f94fc2db: Pull complete
f98254a2b688: Pull complete
6ad83e89f981: Pull complete
a42d733ea779: Pull complete
6fd1af2601dd: Pull complete
0233a63dc5cd: Pull complete
5f31e56c9bea: Pull complete
c0fb96d14e5b: Pull complete
d57074c62694: Pull complete
7030c241d9b8: Pull complete
Digest: sha256:2be51594eba5983f47e67ff5cb87d666a223e309c6c64450f30b5c59a788ea40
Status: Downloaded newer image for mysql:latest
4、总结
本文档针对Docker拉取镜像超时问题,提供通过配置国内镜像源的解决方案,包含编辑daemon.json
文件、执行daemon-reload
和reload
命令加载配置、验证MySQL镜像拉取成功三个关键步骤,方案支持多源冗余且无需重启容器服务
。