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

我正在关注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中的任何内容。

hscooler 回答:离线使用臂架Maven插件构建Docker容器的问题

如果您未指定基本映像,则默认情况下,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>
    

    如果愿意,可以同时指定标记和摘要。但是,在这种情况下,该标记将无效,仅用作注释。

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

    对于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
    

运行本地Docker守护程序时的另一种选择是,通过在基础映像的前面加上docker://(例如<image>docker://openjdk:11-jre-slim</image>),使Jib使用守护程序中的映像。但是,视情况而定,这可能会比使用远程基本映像慢一些(但即使在这种情况下也可能不会那么慢)。


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

本文链接:https://www.f2er.com/2452508.html

大家都在问