[英]Automated Spring boot Docker Image failed to build on docker hub when connected to github/bitbucket repository
I have a simple Dockerfile in my spring boot as follow. 我在春季引导中有一个简单的Dockerfile,如下所示。 I am able to build the image successfully locally, and can push using my credentials. 我能够在本地成功构建映像,并且可以使用我的凭据进行推送。
But my build keeps failing on every attempt to build automatically. 但是我的构建在每次自动构建的尝试中始终失败。
FROM openjdk:8-jdk-alpine LABEL maintainer="xxxxx@xxx.com" VOLUME /tmp EXPOSE 8080 ARG JAR_FILE=target/jollof.jar ADD ${JAR_FILE} jollof.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","- jar","/jollof.jar"]
From docker hub, I got this from the log. 从docker hub,我从日志中得到了这个。
Building in Docker Cloud's infrastructure... Cloning into '.'... Warning: Permanently added the RSA host key for IP address 'xxx.xx.xxx.xxx' to the list of known hosts. .... .... Step 6/7 : ADD ${JAR_FILE} jollof.jar ADD failed: stat /var/lib/docker/tmp/docker- builder674045875/target/jollof.jar: no such file or directory
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. 与您的本地环境不同,Docker Hub会在一个全新的环境中进行获取,然后构建您的项目,因此,要复制的文件target/jollof.jar
在Docker上下文中不可用。 Hence the error you observe. 因此,您观察到错误。
So I'd 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). 因此,我建议重构您的Dockerfile
,以便在Dockerfile
本身中完成mvn package
(出于可再现性的考虑,这是最佳做法)。 Note that this configuration will be working for Docker Hub's automated builds as well as the builds in your local environment. 请注意,此配置将适用于Docker Hub的自动构建以及您本地环境中的构建。
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? 例如,下面是一个示例Dockerfile
,该示例Dockerfile
SO解答的启发。 如何将Spring-Boot Web服务转换为Docker映像? as well as the Dockerfile
of your post: 以及您的帖子的Dockerfile
:
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 Docker's multi-stage build to get a smaller image based on JRE
FROM openjdk:8-jre-alpine
LABEL maintainer="xxxxx@xxx.com"
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"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.