1

我有一个 Spring Boot maven 应用程序,我需要使用 jib 插件对其进行 dockerize,并将其发送到 azure 容器注册表注册表已设置并准备就绪,包括用户名、密码等...我的 pom.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <jib-maven-plugin.version>1.7.0</jib-maven-plugin.version>
        <docker.image.prefix>containerregistry0001968.azurecr.io</docker.image.prefix>
        <java.version>1.8</java.version>
        <username>containerregistry0001968</username>
        <password>/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD</password>
        <project.artifactId>demo-springboot-docker-0001968</project.artifactId>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-servicebus-jms-spring-boot-starter</artifactId>
            <version>2.1.7</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>jib-maven-plugin</artifactId>
                <groupId>com.google.cloud.tools</groupId>
                <version>1.8.0</version>
                <configuration>
                    <from>
                        <image>suranagivinod/openjdk8:latest</image>
                    </from>
                    <to>
                        <image>demo-springboot-docker-0001968</image>
                        <auth>
                            <username>containerregistry0001968</username>
                            <password>/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD</password>
                        </auth>
                    </to>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

当我运行命令“mvn compile jib:build”时,我得到以下输出:

[INFO] Containerizing application to demo-springboot-docker-0001968...
[WARNING] Base image 'suranagivinod/openjdk8' does not use a specific image digest - build may not be reproducible
[INFO] The base image requires auth. Trying again for suranagivinod/openjdk8...
[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry-1.docker.io
[WARNING] 
Got output:

credentials not found in native keychain

[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry.hub.docker.com
[WARNING] 
Got output:

credentials not found in native keychain

[INFO] Executing tasks:
[INFO] [==========                    ] 31.7% complete
[INFO] > pulling base image manifest
[INFO] > building dependencies layer
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.770 s
[INFO] Finished at: 2020-01-23T16:12:25-06:00
[INFO] Final Memory: 38M/410M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:1.8.0:build (default-cli) on project demo: Build image failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/demo-springboot-docker-0001968' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for registry-1.docker.io/library/demo-springboot-docker-0001968: 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

基本映像位于公共 docker hub 存储库中。当我运行 docker pull ... - 我能够毫无问题地拉动它。

如何调整这个 pom 文件,以启用基础镜像?

4

2 回答 2

3

Note the error is for the target image, not the base image.

> make sure your credentials for 'registry-1.docker.io/library/demo-springboot-docker-0001968' are set up correctly.

Also note that the target image refers to the Docker Hub repository (registry-1.docker.io).

If I try your username and password (for Docker Hub),

$ docker login -u containerregistry0001968 -p '/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD'
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password

I get the exact same error message shown in the Jib build log:

incorrect username or password

Your username and password are incorrect. And I would change your password right now, since they are now publicly shown. Or just delete this question.

于 2020-01-23T23:39:20.827 回答
1

你觉得:

基础映像位于公共 docker hub 存储库中

码头工人说:

$ docker pull uranagivinod/openjdk8:latest
Error response from daemon: pull access denied for uranagivinod/openjdk8, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

第一次表演再试一次docker logout,你会发现它实际上是一个私人图像。

于 2020-01-23T23:13:01.293 回答