Builder 生命周期“创建者”失败,状态码为 51

问题描述 投票:0回答:2

在我的 spring boot 应用程序中,当我尝试通过此命令构建我的 docker 镜像时出现问题

mvn spring-boot:build-image -DskipTests

结果是构建失败:

  [INFO] Scanning for projects...
[INFO] 
[INFO] ------< com.in28minutes.microservices:currency-exchange-service >-------
[INFO] Building currency-exchange-service-docker 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:3.0.2:build-image (default-cli) > package @ currency-exchange-service >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ currency-exchange-service ---
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ currency-exchange-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ currency-exchange-service ---
[INFO] skip non existing resourceDirectory C:\Users\vavil\Desktop\spring-microservices\spring-microservices-v3-main\04.docker\currency-exchange-service\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ currency-exchange-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ currency-exchange-service ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ currency-exchange-service ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:3.0.2:repackage (repackage) @ currency-exchange-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] <<< spring-boot-maven-plugin:3.0.2:build-image (default-cli) < package @ currency-exchange-service <<<
[INFO]
[INFO] 
[INFO] --- spring-boot-maven-plugin:3.0.2:build-image (default-cli) @ currency-exchange-service ---
[INFO] Building image 'docker.io/in28min/mmv3-currency-exchange-service:0.0.1-SNAPSHOT'
[INFO]
[INFO]  > Executing lifecycle version v0.16.0
[INFO]  > Using build cache volume 'pack-cache-3c5bb71319ef.build'
[INFO]
[INFO]  > Running creator
[INFO]     [creator]     ===> ANALYZING
[INFO]     [creator]     Previous image with name "docker.io/in28min/mmv3-currency-exchange-service:0.0.1-SNAPSHOT" not found
[INFO]     [creator]     ===> DETECTING
[INFO]     [creator]     6 of 24 buildpacks participating
[INFO]     [creator]     paketo-buildpacks/ca-certificates   3.5.1
[INFO]     [creator]     paketo-buildpacks/bellsoft-liberica 9.10.3
[INFO]     [creator]     paketo-buildpacks/syft              1.24.2
[INFO]     [creator]     paketo-buildpacks/executable-jar    6.6.0
[INFO]     [creator]     paketo-buildpacks/dist-zip          5.5.0
[INFO]     [creator]     paketo-buildpacks/spring-boot       5.22.1
[INFO]     [creator]     ===> RESTORING
[INFO]     [creator]     ===> BUILDING
[INFO]     [creator]
[INFO]     [creator]     Paketo Buildpack for CA Certificates 3.5.1
[INFO]     [creator]       https://github.com/paketo-buildpacks/ca-certificates
[INFO]     [creator]       Launch Helper: Contributing to layer
[INFO]     [creator]         Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
[INFO]     [creator]
[INFO]     [creator]     Paketo Buildpack for BellSoft Liberica 9.10.3
[INFO]     [creator]       https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
[INFO]     [creator]         $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
[INFO]     [creator]         $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
[INFO]     [creator]         $BP_JVM_VERSION              11                                                           the Java version
[INFO]     [creator]       Launch Configuration:
[INFO]     [creator]         $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
[INFO]     [creator]         $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
[INFO]     [creator]         $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
[INFO]     [creator]         $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
[INFO]     [creator]         $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
[INFO]     [creator]         $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
[INFO]     [creator]         $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
[INFO]     [creator]         $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
[INFO]     [creator]         $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
[INFO]     [creator]         $BPL_JMX_PORT                5000                                                         configure the JMX port
[INFO]     [creator]         $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
[INFO]     [creator]         $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
[INFO]     [creator]         $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
[INFO]     [creator]         $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
[INFO]     [creator]         Using Java version 18 extracted from MANIFEST.MF
[INFO]     [creator]       No valid JRE available, providing matching JDK instead. Using a JDK at runtime has security implications.
[INFO]     [creator]        : Contributing to layer
[INFO]     [creator]       Warning: Dependency has no SHA256. Skipping cache.
[INFO]     [creator]         Downloading from
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to get dependency
[INFO]     [creator]     unable to download
[INFO]     [creator]     unable to request
[INFO]     [creator]     Get "": unsupported protocol scheme ""
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.631 s
[INFO] Finished at: 2023-03-02T10:31:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:build-image (default-cli) on project currency-exchange-service: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3
.0.2:build-image failed: Builder lifecycle 'creator' failed with status code 51 -> [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/PluginExecutionException

我尝试更改我的 pom.xml 以及一些版本以检查是否存在版本兼容性问题,但我仍然面临同样的问题。

这是我的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>3.0.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.in28minutes.microservices</groupId>
    <artifactId>currency-exchange-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>currency-exchange-service-docker</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2022.0.0</spring-cloud.version>
    </properties>


    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>


        <!--        <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-config</artifactId>
                </dependency>
         -->
        <!-- Spring Boot 3+ Tracing -->

        <!-- Micrometer > Brave/OpenTelemetry > Zipkin -->

        <!-- Micrometer - Vendor-neutral application observability facade. Instrument your JVM-based application code without vendor lock-in.  Observation (Metrics & Logs) + Tracing.-->

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-observation</artifactId>
        </dependency>

        <!-- Brave as Bridge -->

        <!--
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-brave</artifactId>
        </dependency>

        <dependency>
            <groupId>io.zipkin.reporter2</groupId
            <artifactId>zipkin-reporter-brave</artifactId>
        </dependency>
        -->

        <!-- Open Telemetry as Bridge -->
        <!-- Open Telemetry - Simplified Observability (metrics, logs, and traces) -->

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>

        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-zipkin</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

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

        <dependency>
            <groupId>io.github.resilience4j</groupId>
            <artifactId>resilience4j-spring-boot2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <name>in28min/mmv3-${project.artifactId}:${project.version}</name>
                    </image>
                    <pullPolicy>IF_NOT_PRESENT</pullPolicy>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

我也试过改这个版本:

<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.2</version>

至:

  <version>2.7.4</version>

但是我在某些类中遇到错误,因为我使用了导入,例如:

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
java spring spring-boot docker docker-image
2个回答
4
投票

尝试下载 JRE 或 JDK 以在生成的图像中使用时,您的图像构建失败。输出显示

Using Java version 18 extracted from MANIFEST.MF
,但输出中显示的用于 BellSoft Liberica 的 Paketo Buildpack (
paketo-buildpacks/bellsoft-liberica 9.10.3
) 不支持 Java 18(有关它支持的版本,请参阅release notes)。

Using Java version 18 extracted from MANIFEST.MF
输出表示Spring Boot生成的jar文件中的
META-INF/MANIFEST.MF
文件包含
Build-Jdk-Spec: 18
行。这不应该是这种情况,因为你上面的
pom.xml
<java.version>17</java.version>
,所以那里看起来不对劲。

您应该确保 jar 清单中的

Build-Jdk-Spec
条目与 Paketo Buildpack for Bellsoft Liberica 支持的 JRE 条目之一匹配(即
17
19
)。 Maven 应该自动设置它,除非构建中的其他东西正在修改 jar 清单。

您还可以选择显式配置 buildpack 以使用您想要的 JRE 版本,如 Spring Boot 文档中所示。

例子:
使用 Java 17 的 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">
    ...
    <properties>
        <java.version>17</java.version>
        ...
    </properties>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- Make sure `mvn spring-boot:build-image` uses the Java version defined in this project -->
                    <image>
                        <env>
                            <BP_JVM_VERSION>${java.version}</BP_JVM_VERSION>
                        </env>
                    </image>
                    ...
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>

</project>

0
投票

解决了我的问题,我在系统中安装了 java-19,但应用程序运行在 java 17 上。因此将下面一行添加到 pom XML 中解决了我的问题并创建了图像。 ${java.version}

© www.soinside.com 2019 - 2024. All rights reserved.