Docker 配置阿里云镜像加速器

时间:2024-10-03 22:05:02

由于国内访问直接访问docker hub网速比较慢,拉取镜像的时间就会比较长。一般我们会使用镜像加速或者直接从国内的一些平台镜像仓库上拉取。

根据网上提供的方案,有网易,daocloud,ustc等解决方案,但是最后还是选择了阿里云的。

网易镜像中心:https://c.163.com/hub#/m/home/ 
daocloud镜像市场:https://hub.daocloud.io/

阿里云 - 开发者平台:https://dev.aliyun.com/
阿里云 - 容器Hub服务控制台:https://cr.console.aliyun.com/

注册并登陆阿里云 - 开发者平台之后,在首页点击“创建我的容器镜像”,然后就会来到阿里云的服务面板。点击加速器标签。
根据提示输入Docker登录时需要使用的密码(后期可更改),用户名就是登录阿里云的用户名。
在出现的页面中,可以得到一个专属的镜像加速地址,类似于“https://1234abcd.mirror.aliyuncs.com”。
根据页面中的“操作文档”信息,配置自己的Docker加速器。

或者,登录阿里云 - 容器Hub服务控制台之后,点击加速器标签,也会出现相应信息。

[root@localhost /]# mkdir -p /etc/docker
[root@localhost /]# tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://tqvgn51t.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://tqvgn53t.mirror.aliyuncs.com"]
}
[root@localhost /]# systemctl daemon-reload
[root@localhost /]# systemctl restart docker

上面命令里面配置的专属地址是假的,请大家不要照抄。

查看:

[root@localhost hongdada]# docker info
Containers:
Running:
Paused:
Stopped:
Images:
Server Version: 1.13.
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: false
Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: docker-init
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: N/A (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: N/A (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
WARNING: You're not using the default seccomp profile
Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.-693.21..el7.x86_64
Operating System: CentOS Linux (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks:
CPUs:
Total Memory: 975.2 MiB
Name: localhost.localdomain
ID: 2QP3:PYDM:BLLS:P5QS:QGJN:N7GK:DAKV:ZWFG:FW54:FHS4:FCAN:6NR4
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/
Registry Mirrors:
https://tqvgn51t.mirror.aliyuncs.com
Live Restore Enabled: false
Registries: docker.io (secure)

看看加粗的地方,就是你的阿里云的专属加速器地址

从阿里云拉取,推送镜像操作:https://cr.console.aliyun.com/?spm=5176.1971733.0.2.MUp3vN#/imageList

登录阿里云docker registry:

$ sudo docker login --username=hongda159505@qq.com registry.cn-hangzhou.aliyuncs.com

登录registry的用户名是您的阿里云账号全名,密码是您开通服务时设置的密码。

你可以在镜像管理首页点击右上角按钮修改docker login密码。

从registry中拉取镜像:

$ sudo docker pull registry.cn-hangzhou.aliyuncs.com/hongdada/job1:[镜像版本号]

将镜像推送到registry:

$ sudo docker login --username=hongda159505@qq.com registry.cn-hangzhou.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/hongdada/job1:[镜像版本号]
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/hongdada/job1:[镜像版本号]

其中[ImageId],[镜像版本号]请你根据自己的镜像信息进行填写。

https://blog.****.net/u014231523/article/details/61197945

https://ieevee.com/tech/2016/09/28/docker-mirror.html

https://www.jianshu.com/p/1a4025c5f186

https://www.cnblogs.com/anliven/p/6218741.html