解决docker-maven-plugin Push Exception caught: no basic auth credentials

在尝试使用Maven 插件docker-maven-plugin 打包推送镜像的时候

docker-maven-plugin插件push 一直失败,最终推送失败。

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.0:build (default-cli) on project discovery-service: Exception caught: no basic auth credentials -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

报了找不到凭证的异常。

我们到该插件开发作者的githubissues - mvn -DpushImage Fail : no basic auth credentials#309

tdelesio commented on 1 Apr 2017: One thing I would recommend that really tripped me up was the version of the plugin. I was using a very old plugin version and it was giving me this error. When I changed to the current version it magiclly worked.

这个问题似乎是由于版本问题导致的,所以使用低版本就可以解决问题,这里为了解决这个问题我使用1.1.1的版本。配置如下

<properties>
	<docker.registry>locahost:5000</docker.registry>
</properties>
<plugins>
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
        <imageName>${docker.registry}/${project.name}:${project.version}</imageName>
        <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
        <skipDockerBuild>false</skipDockerBuild>
        <pushImage>true</pushImage>
        <serverId>nexus</serverId>
        <registryUrl>${docker.registry}</registryUrl>
        <resources>
            <resource>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>
</plugins>

该配置中,配置了远程私有私服的相关信息。(如认证凭证和仓库地址)

<serverId>nexus</serverId>
<registryUrl>${docker.registry}</registryUrl>

由于使用的是私服,所以还需要在Maven的配置文件settings.xml中设置,serviceId配置私服认证的ID和口令。

<servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin</password>
    </server>
</servers>

这样在pom.xml的文件中运行下面命令,就可以自动打包并且推送到私服仓库中

mvn clean package docker:build
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值