我按照此处的步骤将 docker 图像推送到 Google Cloud Registry 。
我可以手动运行docker push eu.gcr.io/[PROJECT_ID]/[IMAGE_TAG]
,它会成功运行。但是,由于缺少凭据,dockerfile maven 插件会失败:
org.apache.maven.plugin.MojoExecutionException: Could not push image
...
Caused by: com.spotify.docker.client.exceptions.DockerException: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
此时,我的~/.docker/config.json
文件如下所示:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
经过大量调试,我找到了一个有效的配置:
{
"auths": {
"eu.gcr.io": {}
},
"credHelpers": {
"eu.gcr.io": "gcr"
},
"credsStore": "gcr"
}
我必须安装docker-credential-gcr
模块:
gcloud components install docker-credential-gcr
我有两个问题:
- 为什么我需要以这种方式更改我的配置?
- 是否值得在GitHub 上提出问题,或者这是我设置的一个奇怪的怪癖?
编辑:
我的 Maven 配置的相关部分是:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<repository>eu.gcr.io/[PROJECT_ID]/[IMAGE_NAME]</repository>
<tag>2.0.0</tag>
</configuration>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
<execution>
<id>tag-image-latest</id>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
</executions>
</plugin>