代码之家  ›  专栏  ›  技术社区  ›  Eugene Goldberg

如何将maven项目与jib正确对接

  •  0
  • Eugene Goldberg  · 技术社区  · 5 年前

    我有一个Spring Boot maven应用,我需要使用jib插件将其停靠,并发送到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
    

    如何调整这个pom文件,以便能够提取基础图像?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Zeitounator Vladimir Botka    5 年前

    你认为:

    Docker说:

    $ 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 你会发现这其实是一个私人形象。

        2
  •  0
  •   Chanseok Oh    5 年前

    注意它是目标图像,而不是基础图像。

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

    还要注意的是Docker Hub存储库。

    如果我试试你的用户名和密码(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
    

    使用Jib时请注意相同的错误消息:

    incorrect username or password
    

    您的用户名和密码不正确。我会马上更改你的密码,因为他们现在已经公开了。或者删除这个问题。

    推荐文章