8
votes

I have a simple SpringBoot application and I want to build docker image using Jib Maven plugin. Following is my plugin configuration:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>2.1.0</version>
    <configuration>
        <from>
            <image>openjdk:11-jdk-slim</image>
        </from>
        <to>
            <image>username/appname</image>
            <tags>
                <tag>latest</tag>
                <tag>${project.version}</tag>
            </tags>
        </to>
        <container>
            <mainClass>demo.Application</mainClass>
            <ports>
                <port>8080</port>
                <port>8787</port>
            </ports>
        </container>
    </configuration>
</plugin>

I just want to build the image locally and run it. I don't want to build and push to docker registry in one go.

When I run the command mvn jib:build it is automatically getting pushed to DockerHub using my credentials from Docker config (/Users/username/.docker/config.json).

Is there a way I can disable push and another goal just to push the image to registry?

3
did u try mvn jib:dockerBuild ?pvpkiran
Using jib:dockerBuild is only building the image without pushing but it needs docker daemon running right? The primary reason for choosing jib is we don't need to have Docker daemon running on CI servers.K. Siva Prasad Reddy

3 Answers

4
votes

Since you said jib:dockerBuild is not an option, the closest workaround is jib:buildTar; the goal creates a local tarball at target/jib-image.tar (path configurable with <outputPaths><tar>). Running jib:buildTar (or any jib:... goals) for the first time will build and cache everything necessary to build an image. Therefore, subsequent jib:build runs will be no-op in terms of building layers. It will only need to send layers missing in a remote registry.

Of course, one downside of the workaround is that it creates an unnecessary tarball, which may be large.


Unrelated to you question, you don't need to set <tag>latest</tag>, because the target image reference <image>username/appname<image> already implies <image>username/appname:latest<image>. The <tags> configuration is for pushing additional tags on top of <to><iamge>.

3
votes

From JIB documentation Jib Maven Plugin, you can run

mvn jib:dockerBuild

This will push an image to a Docker daemon after building.

0
votes

I just checked and it is possible to have the image built by Jib locally. First make sure that your Docker daemon is running locally. And then do it like this:

    <to>
        <image><your-local-image-name></image>
    </to>

I guess yours might not have worked because your Docker daemon wasn't running or your image name started with your username, which made Jib think that you actually want to push the image to Docker Hub.