简体   繁体   中英

Dockerfile to create image of spring boot

I want to create Docker image for a spring boot application.It uses gardle as build tool.

In bitbucket repository i could see below files are placed

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

Now Dockerfile has below content

  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

    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? Also where target/dependency/ will be created?

why here there is no gradle build steps in docker file?

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 .

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.

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.

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.

When working With Gradle ur jar file is going to be generated inside build/libs/{Your jar}

Can you please change ARG DEPENDENCY=target/dependency to ARG DEPENDENCY=build/libs and try? It will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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