Problem with using jib maven plugin offline for building docker container

Tags: , , , ,



I’m following Spring Boot Docker Tutorial from here.

I got the exact result while having an internet connection. Now I need to produce the same result in an environment without an internet connection. I copied maven repositories and docker image into the new environment. I’m quite sure maven and docker is up and running.

When I tried to run following command com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=eureka I’m getting error messages. 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

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.

Answer

If you do not specify a base image, Jib by default uses gcr.io/distroless/java:8 as a base image for Java 8 apps.

When you are not using a specific image digest (such as gcr.io/distroless/java@sha256:...) but instead use a tag (:8 in this case) for a base image, the tag can point to different images over time. That is, if you build an image sometime later, Jib may pick up a slightly different base image than before. 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. If not, Jib will download the updated image. This is why you are getting the error.

You have two options.

  1. Pass --offline to Maven on the command-line. Then, Jib will use the cached base image; there will be no online connection. Of course, for this to work, Jib should have cached the base image before; you need to run Jib at least once online for --offline to work later.

  2. Use a digest to pin down a specific base image. For example, in your pom.xml,

    <configuration>
      <from><image>gcr.io/distroless/java@sha256:e99eb6cf88ca2df69e99bf853d65f125066730e3e9f7a233bd1b7e3523c144cb</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>gcr.io/distroless/java:8@sha256:e99eb6cf88ca2df69e99bf853d65f125066730e3e9f7a233bd1b7e3523c144cb</image></from>
    

    For Google Cloud Registry, you can visit https://gcr.io/distroless/java to look for image digests in the repository. Another way to find a digest is to run Jib once online. After the warning, you will see a message reporting the current digest for tag.

    [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
    

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>). 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. Jib does not use Dockerfile, Docker CLI, or Docker daemon.



Source: stackoverflow