Dockerfile春季靴子
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在扩展这样的模式时,Docker使用普通的外壳球体规则;没有办法告诉它使用最新的匹配文件,或具有最大嵌入式语义版本或其他内容的文件。
当您构建图像时,您可以将
arg
的更具体的值传递给您可能也希望该构建版本在图像标签中,并且对此可能会有所帮助。
(您可能不需要在重建之间进行
./ 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
likeYou 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.)