简体   繁体   English

Dockerfile 创建 spring 启动映像

[英]Dockerfile to create image of spring boot

I want to create Docker image for a spring boot application.It uses gardle as build tool.我想为 spring 启动应用程序创建 Docker 映像。它使用 gardle 作为构建工具。

In bitbucket repository i could see below files are placed在 bitbucket 存储库中,我可以看到放置了以下文件

    --> src
    --> build.gradle
    --> Dockerfile
    --> gradlew
    --> gradlew.bat

Now Dockerfile has below content现在 Dockerfile 有以下内容

  FROM openjdk:8-jdk-alpine
  VOLUME /tmp
  ARG DEPENDENCY=target/dependency
  COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
  COPY ${DEPENDENCY}/META-INF /app/META-INF
  COPY ${DEPENDENCY}/BOOT-INF/classes /app
  EXPOSE 8080
  ENTRYPOINT ["java","-cp","app:app/lib/*","eds.billnq"]

When i try to create image using Dockerfile i get error当我尝试使用 Dockerfile 创建图像时出现错误

    target/dependency/BOOT-INF library not found 
    target/dependency/META-INF library not found

My query is why here there is no gradle build steps in docker file?我的问题是为什么 docker 文件中没有 gradle 构建步骤? Also where target/dependency/ will be created?还将在哪里创建目标/依赖项/?

why here there is no gradle build steps in docker file?为什么 docker 文件中没有 gradle 构建步骤?

It looks like the Dockerfile is expecting the application to have already been built (by Gradle) before the Docker image is built, and for the resulting class files and jars to be available in various directories under target/dependency . It looks like the Dockerfile is expecting the application to have already been built (by Gradle) before the Docker image is built, and for the resulting class files and jars to be available in various directories under target/dependency .

The Spring Boot Docker guide referred to by @WonChul Heo in the comments goes into how to build a Docker image using Gradle and specifically with the plugin gradle.plugin.com.palantir.gradle.docker:gradle-docker . The Spring Boot Docker guide referred to by @WonChul Heo in the comments goes into how to build a Docker image using Gradle and specifically with the plugin gradle.plugin.com.palantir.gradle.docker:gradle-docker .

Also where target/dependency/ will be created?还将在哪里创建目标/依赖项/?

I'm guessing they should be created when you run your Gradle build, but without knowing more about how the build is configured, it's hard to say for sure.我猜它们应该是在您运行 Gradle 构建时创建的,但是如果不了解更多关于构建如何配置的信息,很难确定。

I suggest you read through the guide again and compare what it recommends to what you have in your codebase, especially the Gradle build definitions.我建议您再次阅读该指南,并将其推荐的内容与您的代码库中的内容进行比较,尤其是 Gradle 构建定义。

At the end of the day, if you've pulled code from a private code repo and can't figure out how to make it build, it's probably best to seek out advice from the people who've committed to the codebase than from SO.归根结底,如果您从私人代码仓库中提取代码并且无法弄清楚如何构建它,那么最好向致力于代码库的人寻求建议,而不是向 SO .

When working With Gradle ur jar file is going to be generated inside build/libs/{Your jar}使用 Gradle 时,您的 jar 文件将在build/libs/{Your jar}中生成

Can you please change ARG DEPENDENCY=target/dependency to ARG DEPENDENCY=build/libs and try?您能否将ARG DEPENDENCY=target/dependency更改为ARG DEPENDENCY=build/libs并尝试? It will work.它会起作用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM