Spotify docker-maven-plugin 未授权:需要身份验证 public 回购

Spotify docker-maven-plugin unauthorized: authentication required public repo

我无法使用以下命令将 docker 图像推送到集线器:

mvn clean package docker:build -DpushImage

每次我收到以下回复:

[WARNING] Failed to push jdruwe/k8s-product-owner, retrying in 10 seconds (5/5).

...

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project k8s-product-owner: Exception caught: unauthorized: authentication required -> [Help 1]

当我尝试使用以下命令之一登录时,即使登录成功,我仍然会收到错误消息

docker login -u jdruwe https://index.docker.io/v1/

OR

docker login

我确实在 hub 上创建了一个空的 repo 只是为了尝试修复它:

有什么想法吗?

您是否正确配置了身份验证设置?

可以在settings.xml中设置用户和密码:

<servers>
  <server>
    <id>docker-hub</id>
    <username>jdruwe</username>
    <password>secret-password</password>
    <configuration>
      <email>foo@foo.bar</email>
    </configuration>
  </server>
</servers>

然后,pom 引用这些设置:

 <plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>VERSION GOES HERE</version>
  <configuration>
    [...]
    <serverId>docker-hub</serverId>
    <registryUrl>https://index.docker.io/v1/</registryUrl>
  </configuration>
</plugin>

可以在这里找到更详细的信息:https://github.com/spotify/docker-maven-plugin#authenticating-with-private-registries

上述变通办法就像魔术一样奏效。但是,settings.xml 文件在我的机器上丢失了。如下在我的机器上的 /Users/username/.m2 目录下创建 setttings.xml 并且有效

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>docker.io</id>
            <username>your_username</username>
            <password>your_password</password>
        </server>
    </servers>
</settings>