maven 401使用jib创建Docker图像时未经授权

neekobn8  于 2022-11-22  发布在  Maven
关注(0)|答案(6)|浏览(369)

我在Windows上,这是插件配置:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.2.1</version>
    <configuration>
        <container>
            <ports>
                <port>8080</port>
            </ports>
            <format>OCI</format>
        </container>
    </configuration>
</plugin>

下面是我运行的命令:

.\mvnw clean install jib:dockerBuild -Dimage=fullstack:v1

无论我做什么,我总是会遇到这样的错误:

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.2.1:dockerBuild (default-cli) on project SpringBootFullStack: Build
 to Docker daemon failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/eclipse-temurin' are set up correc
tly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized f
or help: Unauthorized for registry-1.docker.io/library/eclipse-temurin: 401 Unauthorized
[ERROR] {"details":"incorrect username or password"}
[ERROR] -> [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

我应该怎么做呢?我已经阅读了jib github repo上的认证文档,但我真的不明白如何进行,感到不知所措
更新
我运行docker login,得到:

Authenticating with existing credentials...
Login Succeeded

但错误仍然存在(我想我可能没有包括日志记录的某些部分:

[INFO] Using credentials from Docker config (C:\Users\david\.docker\config.json) for openjdk:17
[INFO] Executing tasks:                               
[INFO] [============                  ] 40.0% complete
[INFO] > building image to Docker daemon              
[INFO]                                                
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.964 s
[INFO] Finished at: 2022-05-17T19:39:12+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.2.1:dockerBuild (default-cli) on project SpringBootFullStack: Build
 to Docker daemon failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/openjdk' are set up correctly. See
 Unauthorized for registry-1.docker.io/library/openjdk: 401 Unauthorized
[ERROR] {"details":"incorrect username or password"}
[ERROR] -> [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

更新2
这也是文件日志为获取用户名和密码而参考的内容:

{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "credsStore": "desktop"
}

更新3
经过两天的尝试,我决定寻找其他能做同样工作的东西:有了这个,工作在10分钟内就完成了。生活真的很疯狂

1u4esq0p

1u4esq0p1#

只需从docker-config文件中删除credsStore属性,即可在用户主目录中找到config.json。
路径为:$USER/. docker/config.json并假设该文件包含以下内容,

{
  "auths": {
    "https://index.docker.io/v1/": {}
  },
  "credsStore": "desktop"
}

现在删除行:“信用存储”:“桌面”
因此,该文件现在将包含以下内容

{
  "auths": {
    "https://index.docker.io/v1/": {}
  }
}
ljsrvy3e

ljsrvy3e2#

{"details":"incorrect username or password"}

来自服务器的响应是明确的。凭据被给予服务器,它说它们是错误的。
事实上,Jib确实从Docker config.json文件中检索到了一些(可能是不工作的)凭证:

[INFO] Using credentials from Docker config (C:\Users\david\.docker\config.json) for openjdk:17

尝试清空整个config.json或删除文件。特别是删除"https://index.docker.io/v1/"credsStore的条目。
可能是同样的问题,以这个Stack Overflow question。也看看这个GitHub issue的Jib回购。

ozxc1zmp

ozxc1zmp3#

我在Mac上也遇到了同样的问题。我找到了两种解决方法:
1.为此,您可以使用吊臂配置:

<configuration>
  ...
  <from>
    <image>aws_account_id.dkr.ecr.region.amazonaws.com/my-base-image</image>
    <auth>
      <username>my_username</username>
      <password>my_password</password>
    </auth>
  </from>
  <to>
    <image>gcr.io/my-gcp-project/my-app</image>
    <auth>
      <username>${env.REGISTRY_USERNAME}</username>
      <password>${env.REGISTRY_PASSWORD}</password>
    </auth>
  </to>
  ...
</configuration>

https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md#auth-object
1.第二种方法不是关于Windows,我在Mac OS上修复了这个问题,但你可以尝试使用我的经验。我想,这是奇怪的,如果我们得到401未授权,最有可能的Jib试图登录与一些错误的凭据。在我的情况下,我发现2行钥匙链访问:

  • 第一个(错误)用邮箱换密码(改为真实的密码))
  • 第二个(正确)与真实的的密码Jib试图使用第一个。删除第一个值后问题解决了。在windows的情况下,您可以尝试使用Credential Manager或找到一些其他的凭据存储。

另外,当我在研究它的时候,我发现了一些改变的建议:

"credsStore": "desktop" -> "credStore": "desktop"

但对我没用。

vxf3dgd4

vxf3dgd44#

我在Windows上遇到了同样的问题。请尝试删除以下凭据:

  • ..停靠../访问令牌
  • ..停靠../刷新令牌

https://i.stack.imgur.com/G9aGR.png

nkkqxpd9

nkkqxpd95#

如果您不想执行额外的凭证配置步骤,请在运行mvn package时传递它们,如下所示:

mvn package -D jib.to.auth.username="yourdockerUsername" -Djib.to.auth.password="yourDockerPassword"

它将根据需要构建并推送到Docker Hub。

omvjsjqw

omvjsjqw6#

我在windows上遇到了这个问题,并解决了如下问题:
控制面板\所有控制面板项目\凭据管理器
从这里,我已经删除了Generic Credentials部分中与Docker相关的所有条目
powershell提示符中的:
Docker登录
而且成功了!

相关问题