问题描述
今天从Dockerhub拉取镜像的时候报了一个错误,如下:
➜ ~ docker pull curlimages/curl
Using default tag: latest
Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
从日志上看到,我已经达到了拉取的上限了。但我之前从来没有听说过有这样的限制。
使用Dockerhub账号
首先点击进入参考的文档,可以看到这是前几天刚刚生效的限制,用于限制匿名账户和免费账户每6个小时分别限制为100和200个容器。
在看到这个文档的时候,我意识到一直以来都是以匿名的形式来拉取镜像,所以当出现这个问题的时候,是限制到了每6个小时100的阈值内。所以此时我尝试登陆账号来进行拉取:
[centos@master ~]$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: wangjianchong
Password:
WARNING! Your password will be stored unencrypted in /home/centos/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[centos@master ~]$ docker pull curlimages/curl
Using default tag: latest
latest: Pulling from curlimages/curl
aad63a933944: Pull complete
d47e05aac27c: Pull complete
fd1e9b16f149: Pull complete
4863971a917c: Pull complete
6278c6418410: Pull complete
0ad811736efa: Pull complete
da1a9375412a: Pull complete
77b6e91e3346: Pull complete
ed8f8949fec1: Pull complete
Digest: sha256:5329ee280d3d91f3e48885f18c884af5907b68c6aa80f411927a5a28c4f5df07
Status: Downloaded newer image for curlimages/curl:latest
将用户名密码写到配置中
当我重新开启一个新的终端,想再拉取新的镜像的时候会发现:
[centos@master ~]$ docker pull nginx
Using default tag: latest
Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
还是会报相同的错,需要再次登陆,那有没有一劳永逸的办法?肯定是有的,我们可以把用户名密码写到配置中,这样在每次拉取镜像的时候就不需要额外登陆了。
[centos@master ~]$ cat ~/.docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "aGhoaDpoaGhoCg=="
}
}
}
其中,auth字段内容就是username:password 的base64 编码。配置完成后,我们在执行docker pull nginx
即可拉取最新的nginx镜像即可成功。
原因分析
检测拉取次数原理是同一个IP一个时间范围内不应该拉取过多次数。公司的测试机都是虚拟机,都是同一IP的。
缺点
将用户名密码写到配置文件中是不安全的。如何将登陆凭证进行安全存储,可以参考REFERENCE最后一个链接。
后续
当我在rancher部署的kubernetes集群中的一台slave机器配置了docker的配置文件后,集群上的每一台机器都同步到了。但是仍旧出现了上述的问题,所以我当天就下班了(滑稽脸)。
第二天来上班发现所有的pod一起成功运行了,有点奇怪。不清楚k8s是怎样怎样使用docker来拉取新镜像的。不过这个问题并没有影响本篇文章关于toomanyreqeust问题的处理。
REFERENCE
Increase Rate Limitswww.docker.comDocker Login登录凭证安全存储youendless.com