我正试图从我的Jenkins推送到Google容器注册表。这些构建在Kubernetes Jenkins插件中运行,该插件使用gcr.io/cloud-solutions-images/jenkins-k8s-slave将docker镜像构建到Kubernetes原生Docker中。
在对Google容器注册表进行身份验证后,我正在尝试推送新构建的映像。这是我的管道脚本:
def imageTag = 'gcr.io/project-id/tag'
def version = version from pom
sh './mvnw package'
sh "docker build -t $imageTag:$version ."
sh('gcloud auth activate-service-account --key-file=$FILE')
sh('docker login -p $(gcloud auth print-access-token) -u _token https://gcr.io')
sh("gcloud docker -- push $imageTag:$version")
推送失败,输出如下:
c6ff94654483: Preparing
209db64c273a: Preparing
762429e05518: Preparing
2be465c0fdf6: Preparing
5bef08742407: Preparing
c6ff94654483: Retrying in 5 seconds
5bef08742407: Retrying in 5 seconds
209db64c273a: Retrying in 5 seconds
2be465c0fdf6: Layer already exists
762429e05518: Layer already exists
c6ff94654483: Retrying in 4 seconds
5bef08742407: Retrying in 4 seconds
209db64c273a: Retrying in 4 seconds
c6ff94654483: Retrying in 3 seconds
5bef08742407: Retrying in 3 seconds
209db64c273a: Retrying in 3 seconds
c6ff94654483: Retrying in 2 seconds
5bef08742407: Retrying in 2 seconds
209db64c273a: Retrying in 2 seconds
c6ff94654483: Retrying in 1 second
5bef08742407: Retrying in 1 second
209db64c273a: Retrying in 1 second
5bef08742407: Retrying in 10 seconds
...
unexpected EOF
此问题的根本原因是您的docker守护程序未使用推送到gcr.io所需的凭据进行身份验证。对于原始问题,我认为这可能是因为使用的用户帐户是_token
而不是oauth2accesstoken
。
我遇到了类似的错误,除了使用docker login
而不是使用docker-credential-gcr
,我得到了相同的unexpected EOF
错误。
我的问题是我在GCE上运行,docker-credential-gcr
正在检测并通过GCE元数据API使用不同的服务帐户。
因此,对于遇到此问题的其他人在GCP上运行并尝试通过docker-credential-gcr
对服务帐户进行身份验证时,您需要告诉它只查看gcloud
凭据,而不是查看环境中的元数据API详细信息。我的流程现在看起来像这样:
gcloud auth activate-service-account --key-file=$FILE
docker-credential-gcr configure-docker --token-source="gcloud"
docker push gcr.io/....
希望它可以帮助某人。
请检查是否
sh“docker build --no-cache -t $ imageTag:$ version。”
解决它
在我的情况下,我在尝试以各种方式推送到GCR时发现了类似的“重试”问题,已经根据Google Cloud Services packaged tutorial在GKE上安装了Jenkins。
我使用默认服务帐户来解决遇到此问题的从属服务器。这将继承GCE集群OAuth作用域,默认情况下,这些作用域不具有云存储的写入权限。 Google Cloud控制台会在Kubernetes群集的权限下显示此信息。它显示了Storage: Read Only
,不幸的是它无法改变。
我最终添加了一个新的节点池,如this excellent article中所述,然后删除原始节点池。 create命令看起来像
gcloud container node-pools create pool-3 --cluster my-cluster --zone europe-west1-b --num-nodes=3 --scopes https://www.googleapis.com/auth/devstorage.read_write --machine-type g1-small
执行此操作后,推送工作,GKE集群上的权限列表显示Storage: Read Write
。
检查是否在Cannot push image to repository in Google Container Engine中解决了在tag中使用正确的projectID