离线使用臂架Maven插件构建Docker容器时遇到的问题

问题描述 投票:0回答:1

我正在关注here的Spring Boot Docker教程。

我在连接互联网时得到了确切的结果。现在,我需要在没有Internet连接的环境中产生相同的结果。我将Maven存储库和Docker映像复制到了新环境中。我非常确定maven和docker已启动并正在运行。

[当我尝试运行以下命令com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=eureka时,我收到错误消息。我猜有一些文件插件无法找到,但不确定哪个文件。

我正在添加错误消息

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< com.ays:eureka >---------------------------
[INFO] Building eureka 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- jib-maven-plugin:2.1.0:dockerBuild (default-cli) @ eureka ---
[INFO]
[INFO] Containerizing application to Docker daemon as eureka...
[WARNING] Base image 'gcr.io/distroless/java:8' does not use a specific image digest - build may not be reproducible
[ERROR] I/O error for image [gcr.io/distroless/java]:
[ERROR]     org.apache.http.conn.ConnectTimeoutException
[ERROR]     Connect to gcr.io:443 [gcr.io/64.233.184.82] failed: connect timed out
[INFO] Executing tasks:
[INFO] [============                  ] 40,0% complete
[INFO] > building image to Docker daemon
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  22.409 s
[INFO] Finished at: 2020-04-13T16:37:23+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.1.0:dockerBuild (default-cli) on project eureka: Connect to gcr.io:443 [gcr.io/64.233.184.82] failed: connect timed out -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

有人可以指出我应该去哪里,或者我现在缺少什么?

这是我的DockerFile

FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","hello.Application"]`

我没有在DockerFile中进行任何更改。

java spring-boot docker maven-plugin jib
1个回答
1
投票

如果未指定基本映像,则默认情况下,Jib将gcr.io/distroless/java:8用作Java 8应用程序的基本映像。

[当您不使用特定的图像摘要(例如gcr.io/distroless/java@sha256:...),而是对基础图像使用标签(在这种情况下为:8)时,标签会随着时间指向不同的图像。也就是说,如果您稍后再构建映像,Jib可能会获得与之前略有不同的基本映像。因此出现以下警告:

[WARNING] Base image 'gcr.io/distroless/java:8' does not use a specific image digest - build may not be reproducible

因此,当您不使用摘要时,Jib会到达注册表(gcr.io),并检查本地缓存的映像(不在本地Docker引擎缓存中,而是Jib自己的缓存)是否是最新的。如果没有,Jib将下载更新的图像。这就是为什么您得到此错误。

您有两个选择。

  1. 在命令行上将--offline传递给Maven。然后,Jib将使用缓存的基本映像;不会有在线连接。当然,为此,Jib应该已经缓存了基本映像;您需要至少在线运行一次Jib才能使--offline稍后工作。

  2. 使用摘要来固定特定的基本图像。例如,在您的pom.xml中,

    <configuration>
      <from><image>gcr.io/distroless/java@sha256:e99eb6cf88ca2df69e99bf853d65f125066730e3e9f7a233bd1b7e3523c144cb</image></from>
    </configuration>
    

    对于Google Cloud Registry,您可以访问https://gcr.io/distroless/java在存储库中查找图像摘要。查找摘要的另一种方法是在线运行Jib。警告之后,您将看到一条消息,报告标签的当前摘要。

    [WARNING] Base image 'gcr.io/distroless/java:8' does not use a specific image digest - build may not be reproducible
    [INFO] Using base image with digest: sha256:e99eb6cf88ca2df69e99bf853d65f125066730e3e9f7a233bd1b7e3523c144cb
    

最后,您可以删除您的Dockerfile。 Jib不使用Dockerfile,Docker CLI或Docker守护程序。

© www.soinside.com 2019 - 2024. All rights reserved.