使用Palantir Gradle插件构建Docker容器时找不到java – .jar文件

如果我尝试在Windows 10下使用Spring Boot应用程序构建Docker容器,则会出现以下错误:

> Task :docker FAILED
COPY failed: stat /var/lib/docker/tmp/docker-builder711841135/myproject.jar: no such file or directory

我在版本18.03.0-ce-win59(16762)中使用Docker Community Edition,在Java 8中使用Gradle 4.7.

build.gradle(缩写):

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.0.1.RELEASE'
    id "com.palantir.docker" version "0.19.2"
}

version = '2.0.0'
sourceCompatibility = 1.8
group = "com.example"

repositories {
    mavenCentral()
}

bootJar {
    archiveName 'myproject.jar'
}

dependencies {
    ...
}

docker {
    dependsOn(build)
    name "${project.group}/${jar.baseName}"
    files bootJar
}

Dockerfile(顶级项目目录中build.gradle的兄弟):

FROM openjdk:8-jre
COPY build/libs/myproject.jar myproject.jar

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myproject.jar"]

如果我只使用Docker构建Docker容器(没有Gradle),它就能工作.

我怎样才能让Gradle(或Docker?)找到myproject.jar文件?

它适用于docker任务的以下配置:

docker {
    dependsOn build
    name "${project.group}/${jar.baseName}"
    files bootJar.archivePath
    buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}

使用这个略有不同的docker文件:

FROM openjdk:8-jre
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
翻译自:https://stackoverflow.com/questions/49941955/jar-file-not-found-when-building-a-docker-container-with-palantir-gradle-plug-i

转载注明原文:使用Palantir Gradle插件构建Docker容器时找不到java – .jar文件