提问者:小点点

错误:无效或损坏的jarfile /app.jar


我开始使用docker,并尝试对我的Spring Boot应用程序进行dockerize。我使用Spring初始化器生成了这个。我正在使用maven。我的DockerFile如下所示:

FROM java:8-jdk-alpine

COPY ${JAR_FILE} app.jar

WORKDIR /usr/app

EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]

这很简单。

我执行了下一个命令:

docker build -t shortenurl .

我可以在控制台中看到带有docker图像的图像:

但是当我尝试使用命令运行镜像时:docker run-p 8080:8080短链接我得到了这个错误消息:错误:无效或损坏的jarfile /app.jar

我试过不同的配置,但不太确定。有什么建议吗?

谢谢。

这是我的插件pom. xml插件部分:

       <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.2.3</version>
                <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>

这是我在命令之后的日志:docker build-t短链接。

$ docker build -t shortenurl .
Sending build context to Docker daemon  32.89MB
Step 1/5 : FROM java:8-jdk-alpine
 ---> 3fd9dd82815c
Step 2/5 : COPY ${JAR_FILE} app.jar
 ---> 248aa4be697d
Step 3/5 : WORKDIR /usr/app
 ---> Running in 5fcd71c548af
Removing intermediate container 5fcd71c548af
 ---> bc344b970b11
Step 4/5 : EXPOSE 8080
 ---> Running in 46b4e4f8e9b7
Removing intermediate container 46b4e4f8e9b7
 ---> 6b4f55a86a23
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in 838a6052f4c8
Removing intermediate container 838a6052f4c8
 ---> 7d7d272ea42d
Successfully built 7d7d272ea42d
Successfully tagged shortenurl:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

共1个答案

匿名用户

您正在使用spring-boot-maven-plugin构建,但您没有生成可执行jar。将插件的配置更新为:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

你应该没事。