java – Automated Spring boot Docker Image failed to build on docker hub when connected to github/bitbucket repository
Unlike your local environment, Docker Hub fetches then builds your project in a fresh environment, so that the file
target/jollof.jar that is intended to be copied is not available in the docker context. Hence the error you observe.
So Id suggest refactoring your
Dockerfile so that
mvn package or so is done in the
Dockerfile itself (which is a best practice to adopt, for the sake of reproducibility). Note that this configuration will be working for Docker Hubs automated builds as well as the builds in your local environment.
For example, below is an example
Dockerfile that inspired by the that of this SO answer How to convert a Spring-Boot web service into a Docker image? as well as the
Dockerfile of your post:
FROM maven:3.6-jdk-8 as maven WORKDIR /app COPY ./pom.xml ./pom.xml RUN mvn dependency:go-offline -B COPY ./src ./src # TODO: jollof-* should be replaced with the proper prefix RUN mvn package && cp target/jollof-*.jar app.jar # Rely on Dockers multi-stage build to get a smaller image based on JRE FROM openjdk:8-jre-alpine LABEL firstname.lastname@example.org WORKDIR /app COPY --from=maven /app/app.jar ./app.jar # VOLUME /tmp # optional EXPOSE 8080 # also optional ENTRYPOINT [java,-Djava.security.egd=file:/dev/./urandom,-jar,/app/app.jar]