vap*_*pan 10 java spring docker spring-boot docker-image
在我的 Spring Boot 应用程序中,当我尝试通过此命令构建我的 docker 映像时,我出现了一个问题
mvn spring-boot:build-image -DskipTests
Run Code Online (Sandbox Code Playgroud)
我看到结果是构建失败:
[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
Run Code Online (Sandbox Code Playgroud)
我尝试更改我的 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>
Run Code Online (Sandbox Code Playgroud)
我也尝试过改变这个版本:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
Run Code Online (Sandbox Code Playgroud)
到:
<version>2.7.4</version>
Run Code Online (Sandbox Code Playgroud)
但我在某些类中遇到错误,因为我使用导入,例如:
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Run Code Online (Sandbox Code Playgroud)
Sco*_*ick 16
当尝试下载 JRE 或 JDK 以在生成的映像中使用时,您的映像构建失败。输出显示Using Java version 18 extracted from MANIFEST.MF,但输出 ( paketo-buildpacks/bellsoft-liberica 9.10.3) 中显示的 BellSoft Liberica Paketo Buildpack 不支持 Java 18(有关其支持的版本,请参阅发行说明)。
输出Using Java version 18 extracted from MANIFEST.MF表明META-INF/MANIFEST.MFSpring Boot 生成的 jar 文件中的文件包含行Build-Jdk-Spec: 18. 情况不应该是这样,因为你pom.xml上面有<java.version>17</java.version>,所以有些东西看起来不正确。
您应该确保Build-Jdk-Specjar 清单中的条目与 Bellsoft Liberica 的 Paketo Buildpack 支持的 JRE 条目之一匹配(即17或19)。Maven 应该自动设置它,除非构建中的其他内容正在修改 jar 清单。
您还可以选择显式配置构建包以使用所需的 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>
Run Code Online (Sandbox Code Playgroud)
解决了我的问题,我在系统中安装了 java-19,但应用程序运行在 java 17 上。因此,在 pom XML 中添加以下行解决了我的问题并创建了图像。<BP_JVM_VERSION>${java.version}</BP_JVM_VERSION>
| 归档时间: |
|
| 查看次数: |
3788 次 |
| 最近记录: |