Maven 我的命令docker compose up在尝试运行spring boot应用程序时出错
当我运行Maven 我的命令docker compose up在尝试运行spring boot应用程序时出错,maven,spring-boot,docker-compose,Maven,Spring Boot,Docker Compose,当我运行docker compose upspring容器启动但无法访问我的jar时,我正在使用maven插件生成带有构建的Dockerfile 错误: $ docker-compose up postgres_container is up-to-date Starting spring_container ... done Attaching to postgres_container, spring_container spring_container | Error: Unable to
docker compose up
spring容器启动但无法访问我的jar时,我正在使用maven插件生成带有构建的Dockerfile
错误:
$ docker-compose up
postgres_container is up-to-date
Starting spring_container ... done
Attaching to postgres_container, spring_container
spring_container | Error: Unable to access jarfile /demo-0.0.1-SNAPSHOT.jar
我的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.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.lucasmarinzeck</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.7.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>aps-04s</imageName>
<baseImage>openjdk:8-jdk-alpine</baseImage>
<entryPoint>["java ", "-jar ", "/${project.build.finalName}.jar"]</entryPoint>
<exposes>8080</exposes>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我进行了一些搜索,但确实没有找到任何解决此问题的方法。出现错误的原因是:无法访问jarfile/demo-0.0.1-SNAPSHOT.jar,因为该文件不存在
Dockerfile
中的ADD
将自动尝试提取归档文件(而.jar文件就是其中之一)
我的建议是在复制文件时始终使用
COPY
,即使它可以通过ADD
实现。出现错误的原因错误:无法访问jarfile/demo-0.0.1-SNAPSHOT.jar
是因为文件不存在
Dockerfile
中的ADD
将自动尝试提取归档文件(而.jar文件就是其中之一)
我的建议是在复制文件时始终使用
COPY
,即使可以通过ADD
来实现,您可以尝试用下面的行代替ADD吗?复制demo-0.0.1-SNAPSHOT.jar app.jar,然后您的入口点可以是这个。。。ENTRYPOINT[“java”、“-jar”、“/app.jar”]您能用下面的行代替ADD吗?复制demo-0.0.1-SNAPSHOT.jar app.jar,然后您的入口点可以是这个。。。入口点[“java”、“-jar”、“/app.jar”]
FROM openjdk:8-jdk-alpine
ADD /demo-0.0.1-SNAPSHOT.jar /
EXPOSE 8080
ENTRYPOINT ["java ", "-jar ", "/demo-0.0.1-SNAPSHOT.jar"]