推到谷歌容器registry失败:重试
我试图从我的Jenkins推送到Google容器registry。 这个版本在Kubernetes Jenkins Plugin中运行,它使用gcr.io/cloud-solutions-images/jenkins-k8s-slave将Docker镜像构build到Kubernetes本地Docker中。
在对Google容器registry进行身份validation之后,我试图推送新build的图片。 这是我的pipe道脚本:
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所需的凭据进行authentication。 对于原来的问题,我相信这可能是因为正在使用的用户帐户是_token
而不是oauth2accesstoken
。
我遇到类似这样的错误,除了不使用docker login
,而是使用docker-credential-gcr
,并得到相同的unexpected EOF
错误。
我的问题是,我在GCE上运行, docker-credential-gcr
正在通过GCE元数据API检测和使用不同的服务帐户。
因此,对于遇到此问题并且正在运行GCP并尝试通过docker-credential-gcr
validation服务帐户docker-credential-gcr
,您需要告诉它只查看gcloud
凭据,而不是查看元数据API详细信息的环境。 我现在的stream程如下所示:
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”。
解决它