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