19

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?

K. Siva Prasad Reddy
  • 11,786
  • 12
  • 68
  • 95

5 Answers5

18

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>.

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63
7

From JIB documentation Jib Maven Plugin, you can run

mvn jib:dockerBuild

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

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63
nono
  • 1,462
  • 1
  • 13
  • 21
2

If you are using podman in mac or windows (with wsl2)... specify path where podman command can be found

mvn jib:dockerBuild -Djib.dockerClient.executable=$(which podman)
Espresso
  • 5,378
  • 4
  • 35
  • 66
0

Generally, there can be two main reasons someone might want to use Jib instead of Dockerfile inside a project.

  1. To avoid the need of a Docker daemon running in the build/CI nodes.
  2. To avoid the need of a Dockerfile and/or Docker best practices.

Generally, Jib workflow goes from build to container registry. So, the simplest option for you would be to setup a local container registry.

You can try open source Docker Registry or Harbor or something similar.

lkamal
  • 3,788
  • 1
  • 20
  • 34
-3

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.

Tomasz Chudzik
  • 1,867
  • 1
  • 14
  • 21