去年,Docker Hub决定不再提供无限的Docker镜像拉取(参见here)。当你在一家出口IP地址数量有限的大公司里时,这在理论上听起来是合理的,但在实践中会产生一些问题。
因此,我只是想:让我们按照提议的方式,为docker pull命令提供一个用户帐户。即使使用免费帐户,也应该可以每六个小时下载200张图像,这对于现在来说已经足够了,并且可以通过付费帐户进行扩展。
但这说起来容易做起来难。下面是简单的Jenkins管道:
pipeline() {
agent any
stages {
stage('Docker Pull') {
steps {
withDockerRegistry([url: 'https://registry-1.docker.io', credentialsId: '<docker-hub-account>']) {
sh "docker pull maven:3.6.3-openjdk-14"
}
}
}
}
}尽管登录成功,但仍会在构建日志中导致以下错误:
[Pipeline] withDockerRegistry
Using the existing docker config file.$ docker login -u <user> -p ******** https://registry-1.docker.io
Login Succeeded
[Pipeline] {
[Pipeline] sh
+ docker pull docker.io/library/maven:3.6.3-openjdk-14
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
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }所以,简单的问题是:我做错了什么?
只是为了澄清:错误首先发生在简单地运行sh "docker pull maven:3.6.3-openjdk-14"。这就是我添加docker login (Jenkins的withDockerRegistry{...}行)的原因。我只是感到困惑,添加这一行并没有改变任何事情。
PS:检查速率限制,如this blog post输出:RateLimit-Limit: 200和RateLimit-Remaining: 198中所述。
PPS:有大约一百万篇博客文章如何通过使用Docker Hub的镜像来缓解这个问题。我喜欢使用官方的方式,但我只是不确定这应该如何工作……
发布于 2021-01-15 22:22:41
我相信你登录了错误的注册表url。~/.docker/config.json文件中Docker Hub的值为https://index.docker.io/v1/,也为documented by Jenkins。您可以通过运行以下命令来检查该管道中的当前凭据:
pipeline() {
agent any
stages {
stage('Docker Pull') {
steps {
withDockerRegistry([url: 'https://registry-1.docker.io', credentialsId: '<docker-hub-account>']) {
sh "cat ~/.docker/config.json"
}
}
}
}
}凭据是base64编码的,因此您还可以解码以查看user/PASS值是否出错。我还会将其与您在类似linux主机上看到的普通登录进行比较。
假设URL是错误的,调整注册表:
pipeline() {
agent any
stages {
stage('Docker Pull') {
steps {
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: '<docker-hub-account>']) {
sh "docker pull maven:3.6.3-openjdk-14"
}
}
}
}
}在这种情况下,Jenkins DSL可能会更多地阻碍而不是帮助,因为您可以轻松地运行:
pipeline() {
agent any
stages {
stage('Docker Pull') {
steps {
sh "docker login -u $user -p $pass"
sh "docker pull maven:3.6.3-openjdk-14"
}
}
}
}发布于 2021-01-16 00:35:00
这是一个非技术性的答案..。
付钱吧。你滥用了一种不应该免费提供给大公司的资源。这些限制旨在让你付出代价。或者,运行您自己的注册表。
如果“大公司”(你的话)绕过这个限制,你会毁了我们其他人的。作为一名从事小型项目的承包商,我每天都依赖于Docker的免费注册。当我为大银行工作时,我会要求他们支付这笔费用,就像其他所有负担得起的人一样。
https://stackoverflow.com/questions/65732345
复制相似问题