且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-04-14 05:47:28

问题是 COPY 命令:

COPY build/libs/myproject.jar myproject.jar

源目录 build / libs / 不是用于构建Docker容器的文件所在的位置。而是将目录 build / docker / 用作Docker构建上下文。执行 COPY 时,该目录是有效的工作目录。

The source directory build/libs/ is not where the files for building the Docker container reside. Instead the directory build/docker/ is used as Docker build context. When COPY is executed this directory is the effective working directory.

正确的 COPY 命令非常简单:

COPY myproject.jar /

Docker任务:

docker {
    dependsOn bootJar
    name "${project.group}/${jar.baseName}:${version}"
    files bootJar.archivePath
}

如果也要复制资源,需要将 processResources 添加到 files 参数:

If you want to copy resources too, you need to add processResources to the files parameter:

files bootJar.archivePath, processResources