简体   繁体   English

离线使用 jib maven 插件构建 docker 容器的问题

[英]Problem with using jib maven plugin offline for building docker container

I'm following Spring Boot Docker Tutorial from here .我从这里开始关注 Spring Boot Docker 教程。

I got the exact result while having an inte.net connection.我在有 inte.net 连接时得到了准确的结果。 Now I need to produce the same result in an environment without an inte.net connection.现在我需要在没有 inte.net 连接的环境中产生相同的结果。 I copied maven repositories and docker image into the new environment.我将 maven 存储库和 docker 图像复制到新环境中。 I'm quite sure maven and docker is up and running.我很确定 maven 和 docker 已启动并正在运行。

When I tried to run following command com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=eureka I'm getting error messages.当我尝试运行以下命令com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=eureka我收到错误消息。 I guess there are some files plugin cannot locate but not sure which ones.我猜有些文件插件无法找到但不确定是哪些。

I'm adding the error message我正在添加错误消息

[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 

Can somebody point me where should I look or is there anything I'm missing at this point?有人可以指出我应该在哪里看,或者此时我缺少什么吗?

Here is my DockerFile这是我的 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"]`

I didn't change anything in DockerFile.我没有更改 DockerFile 中的任何内容。

If you do not specify a base image, Jib 3.0+ by default uses adoptopenjdk:8-jre as a base image for Java 8 apps.如果不指定基础镜像, Jib 3.0+ 默认使用adoptopenjdk:8-jre作为 Java 8 个应用的基础镜像。 (Prior to 3.0, Jib used gcr.io/distroless/java:8 as the default.) (在 3.0 之前,Jib 默认使用gcr.io/distroless/java:8 。)

When you are not using a specific image digest (such as gcr.io/distroless/java@sha256:... ) but instead use a tag ( :8 in your case with Jib < 3.0) for a base image, the tag can point to different images over time.当您不使用特定的图像摘要(例如gcr.io/distroless/java@sha256:... )而是使用标签(在 Jib < 3.0 的情况下为:8 )作为基本图像时,标签可以随着时间的推移指向不同的图像。 That is, if you build an image sometime later on a different machine, Jib may pick up a slightly different base image than you used before.也就是说,如果您稍后在另一台机器上构建一个镜像,Jib 可能会选择一个与您之前使用的基础镜像略有不同的镜像。 Hence the following warning:因此出现以下警告:

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

For this reason, when you are not using a digest, Jib reaches out to the registry ( gcr.io ) and checks if the locally cached image (not in the local Docker engine cache but Jib's own cache) is up to date.因此,当您不使用摘要时,Jib 会访问注册表 ( gcr.io ) 并检查本地缓存的图像(不是在本地 Docker 引擎缓存中,而是在 Jib 自己的缓存中)是否是最新的。 If not, Jib will download the updated image.如果没有,Jib 将下载更新后的图像。 This is why you are getting the error when you're offline.这就是您在离线时收到错误的原因。

You have two options.你有两个选择。

  1. Pass --offline to Maven on the command-line.在命令行上将--offline传递给 Maven。 Then, Jib will use the cached base image;然后,Jib 将使用缓存的基础图像; there will be no online connection.将没有在线连接。 Of course, for this to work, Jib should have cached the base image before;当然,要实现这一点,Jib 之前应该已经缓存了基础图像; you need to run Jib at least once online beforehand.您至少需要提前在线运行一次 Jib。

  2. Use a digest to pin down a specific base image.使用摘要来固定特定的基本图像。 For example, in your pom.xml ,例如,在您的pom.xml中,

     <configuration> <from><image>adoptopenjdk@sha256:9cb8bc7356ec2d9de56f3be3d8204a846ca0a3220af059aa67c35d53c7138e17</image></from> </configuration>

    If you prefer, you can specify both tag and digest.如果您愿意,可以同时指定标签和摘要。 However, the tag will have no effect and only serve as a comment in this case.但是,在这种情况下,标签将不起作用,仅用作注释。

     <from><image>adoptopenjdk:8-jre@sha256:9cb8bc7356ec2d9de56f3be3d8204a846ca0a3220af059aa67c35d53c7138e17</image></from>

    To find out what digest to use, check the adoptopenjdk Docker Hub repository .要找出要使用的摘要,请查看adoptopenjdk Docker Hub 存储库 Another way is to run Jib once online.另一种方法是在线运行 Jib。 After the warning, you will see a message reporting the current digest for the tag.警告后,您将看到一条消息,报告该标签的当前摘要。

     [WARNING] Base image 'adoptopenjdk:8-jre' does not use a specific image digest - build may not be reproducible [INFO] Using base image with digest: sha256:9cb8bc7356ec2d9de56f3be3d8204a846ca0a3220af059aa67c35d53c7138e17

Another option when you're running a local Docker daemon is to make Jib use an image from the daemon by prefixing docker:// to the base image (for example, <image>docker://openjdk:11-jre-slim</image> ).当您运行本地 Docker 守护程序时,另一种选择是让 Jib 使用来自守护程序的图像,方法是在基本图像docker:// (例如, <image>docker://openjdk:11-jre-slim</image> )。 However, depending on circumstances, this can be a little be slower than using a remote base image (but probably not so much even in that case).但是,根据具体情况,这可能比使用远程基础映像慢一点(但即使在那种情况下也可能不会那么慢)。


Lastly, you can delete your Dockerfile .最后,您可以删除您的Dockerfile Jib does not use Dockerfile , Docker CLI, or Docker daemon. Jib 不使用Dockerfile 、 Docker CLI 或 Docker 守护进程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ClassNotFoundException - 在构建图像时使用 BitBucket 管道中的 jib-maven-plugin 将其推送到 GCR - ClassNotFoundException - when building the image & push it to GCR using jib-maven-plugin in BitBucket pipeline 使用 Jib 插件的 Docker 图像:容器运行时无法在本地命中 rest 端点? - Docker image using Jib plugin: Cant hit rest endpoint locally when container running? 如何使用 maven jib 插件创建多层图像 - How to create muttilayer image using maven jib plugin 使用 Skaffold 和 Jib 构建多模块 maven 项目 - Building a multi module maven project with Skaffold and Jib java maven docker jib 发布端口失败 - java maven docker jib published port fails 使用 Jib 获取特定版本的图像(Maven、Docker、testcontainers) - Getting a specific version of an image with Jib (Maven, Docker, testcontainers) 如何设置 Jib 容器以使用 docker 远程注册表进行身份验证以拉取图像? - How to setup Jib container to authenticate with docker remote registry to pull images? jib-maven-plugin: 如何解决运行扩展错误 - jib-maven-plugin: How to solve running extension error 使用 Jib Maven 插件将 windows nanoserver eclipse-temurin:8 作为基础映像拉取为注册表提供未知的错误 blob - Using Jib Maven Plugin to pull as base image an windows nanoserver eclipse-temurin:8 gives error blob unknown to registry 如何使用 Jib 容器映像为 Quarkus 应用程序设置堆大小? - How to set heap size for Quarkus app using Jib container image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM