经常使用Docker容器的伙伴们会发现,最近各个ocker镜像加速服务全部失效了,下面我总结了几种办法分享给大家,以解燃眉之急。
环境说明
操作系统为CentOS 7
[root@basedocker153 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
Docker的版本为26
[root@basedocker153 ~]# docker version
Client: Docker Engine - Community
Version: 26.1.4
API version: 1.45
Go version: go1.21.11
Git commit: 5650f9b
Built: Wed Jun 5 11:32:04 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 26.1.4
API version: 1.45 (minimum version 1.24)
Go version: go1.21.11
Git commit: de5c9cf
Built: Wed Jun 5 11:31:02 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.33
GitCommit: d2d58213f83a351ca8f528a95fbd145f5654e957
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
失效以后的现象
以某云镜像加速器为例

重启使配置生效
[root@basedocker153 ~]# systemctl daemon-reload
[root@basedocker153 ~]# systemctl restart docker
尝试拉取nginx镜像,显示请求被拒绝
[root@basedocker153 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
e4fff0779e6d: Retrying in 1 second
2a0cb278fd9f: Retrying in 1 second
7045d6c32ae2: Retrying in 1 second
03de31afb035: Waiting
0f17be8dcff2: Waiting
14b7e5e8f394: Waiting
23fa5a7b99a6: Waiting
error pulling image configuration: download failed after attempts=6: dial tcp 179.60.193.16:443: connect: connection refused
尝试解决
方式一 使用GitVerse提供的镜像加速服务
这里以GitVerse Docker Hub Mirror为例,它的官网地址链接: GitVerse
打开页面,里面有使用说明

将https://dh-mirror.gitverse.ru配置为镜像地址即可,编辑daemon.json文件
[root@basedocker153 ~]# vim /etc/docker/daemon.json
填写如下内容
{
"registry-mirrors": ["https://dh-mirror.gitverse.ru"]
}
重启使配置生效
[root@basedocker153 ~]# systemctl daemon-reload
[root@basedocker153 ~]# systemctl restart docker
下载nginx镜像,可以看到已经开始下载了

稍等片刻,镜像下载完毕,很nice

方式二 使用Amazon提供的镜像仓库
我们访问链接: Amazon ECR官网,搜索nginx,同时建议选择Docker 官方镜像

选择第一项

可以看到在About标签中,会说明镜像的详细用法

在images tags标签页中,会显示各个镜像版本的列表,这里我们筛选latest的镜像

点击复制按钮,复制镜像地址

使用镜像地址拉取镜像
[root@basedocker153 ~]# docker pull public.ecr.aws/docker/library/nginx:latest
可以看到镜像已经拉取到本地了

总结
以上两种方式各有优缺点,在实际应用中可以择优使用。

177

被折叠的 条评论
为什么被折叠?



