使用jib创建docker镜像时出现401 Unauthorized

Dav*_* _- 6 java maven docker jib maven-jib

我在 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>
Run Code Online (Sandbox Code Playgroud)

这是我运行的命令:

.\mvnw clean install jib:dockerBuild -Dimage=fullstack:v1
Run Code Online (Sandbox Code Playgroud)

无论我做什么,我都会遇到以下错误:

[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
Run Code Online (Sandbox Code Playgroud)

我该怎么办?我已阅读 jib github repo 上有关身份验证的文档,但我并不真正了解如何进行并感到不知所措

更新

我跑了docker login,得到:

Authenticating with existing credentials...
Login Succeeded
Run Code Online (Sandbox Code Playgroud)

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

[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
Run Code Online (Sandbox Code Playgroud)

更新2

这也是为了获取用户名和密码而引用的文件日志的内容:

{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "credsStore": "desktop"
}
Run Code Online (Sandbox Code Playgroud)

更新3

经过两天的尝试,我决定寻找其他可以完成相同工作的东西: https: //spring.io/guides/gs/spring-boot-docker/ 这样,工作就在大约 10 分钟内完成了。生活真的很疯狂

Kha*_*mon 18

只需从 docker-config 文件中删除 credsStore 属性即可。您将在您的用户主目录中找到 config.json。

路径是:$USER/.docker/config.json 并假设该文件包含以下内容,

{
  "auths": {
    "https://index.docker.io/v1/": {}
  },
  "credsStore": "desktop"
}
Run Code Online (Sandbox Code Playgroud)

现在删除该行:“credsStore”:“desktop”

因此,该文件现在将包含以下内容

{
  "auths": {
    "https://index.docker.io/v1/": {}
  }
}
Run Code Online (Sandbox Code Playgroud)


Ale*_*xey 4

我在 Mac 上也遇到了同样的问题。我找到了两种解决方法:

  1. 为此,您可以使用 jib 配置:
<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>
Run Code Online (Sandbox Code Playgroud)

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"
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用。

UPD Windows 使用同样的情况Credential Manager