Dockerfile春季靴子

发布于 2025-02-09 09:42:49 字数 615 浏览 1 评论 0原文

spring docs 告诉我如何为我的Spring Boot应用程序编写Dockerfile。我使用“ build/libs”目录将其改编成Gradle构建,

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

但是在我的build/libs目录中,我的罐子里有多个版本:

app-22.9.0.jar
app-22.9.0-SNAPSHOT.jar
app-22.10.0.jar
app-22.10.0-SNAPSHOT.jar
...

当然,我可以称呼'Gradle Clean Cossemble'来完成这项工作。但是我也需要测试中的Dockerfile。始终运行干净的组装很烦人。

如何在Dockerfile复制命令中指定仅使用最新JAR。

Spring docs tell me how to write a Dockerfile for my Spring Boot app. I adapted it to my gradle build with "build/libs" directory

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

But in my build/libs directory there are multiple versions of my jar:

app-22.9.0.jar
app-22.9.0-SNAPSHOT.jar
app-22.10.0.jar
app-22.10.0-SNAPSHOT.jar
...

Of course I can call 'gradle clean assemble' to do the job. But I need the Dockerfile in a test too. It is annoying to run clean assemble all the time.

How can I specify in my Dockerfile COPY command to use only the latest jar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲鸠 2025-02-16 09:42:49

在扩展这样的模式时,Docker使用普通的外壳球体规则;没有办法告诉它使用最新的匹配文件,或具有最大嵌入式语义版本或其他内容的文件。

当您构建图像时,您可以将arg的更具体的值传递给

docker build --build-arg JAR_FILE=app-22.10.0.jar -t myapp:22.10.0 .

您可能也希望该构建版本在图像标签中,并且对此可能会有所帮助。

(您可能不需要在重建之间进行./ gradlew Clean,这可能会使运行./ gradlew组装走得更快。)

Docker uses normal shell glob rules when expanding patterns like this; there's no way to tell it to use the single most recent matching file, or the file with the largest embedded semantic version, or other things.

When you build the image, you can pass a more specific value for that ARG like

docker build --build-arg JAR_FILE=app-22.10.0.jar -t myapp:22.10.0 .

You may also want that build version to be in the image tag and it may be helpful to script this.

(You probably don't need to ./gradlew clean in between rebuilds, and that might make running ./gradlew assemble go faster.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文