简体   繁体   English

连接到github / bitbucket存储库时,自动化的Spring Boot Docker Image无法在Docker Hub上构建

[英]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.

相关问题 使用Docker Cloud进行Spring Boot自动构建 - Spring boot automated build with Docker cloud 我未能在 win10 上使用 `mvn spring-boot:build-image` 和远程 docker 守护程序 - I failed to use `mvn spring-boot:build-image` and remote docker daemon on win10 无法解析配置 class,在启动 Spring 启动应用程序时作为 Docker 映像 - Failed to parse configuration class, when starting Spring Boot application as Docker image 构建 docker 镜像时出错,无法在项目上执行目标 org.springframework.boot:spring-boot-maven-plugin:2.5.2:build-image (default-cli) - Error while building docker image, Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.2:build-image (default-cli) on project No main manifest error when running spring 启动微服务 docker image - No main manifest error when running spring boot microservice docker image Java Spring 在 docker 中引导构建 MVN - Java Spring Boot- build MVN in docker com.mysql.cj.jdbc.exceptions.CommunicationsException:尝试构建 spring 引导时通信链接失败 docker 图像 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure when trying to build spring boot docker image 无法使用 Spring Boot 应用程序连接到 docker 映像 - Not able to connect to docker image with a spring boot application 在 Docker 镜像中的 Tomcat 中部署 Spring Boot 应用程序 - Deploying a Spring Boot Application in Tomcat in a Docker image 为 spring 启动应用程序创建 docker 映像的问题 - problem with creating docker image for spring boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM