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?
Jib builds containers without using a Dockerfile or requiring a Docker installation. You can use Jib in the Jib plugins for Maven or Gradle, or you can use the Jib Java library.
Jib is a tool for building images from Java applications without using Docker or Dockerfiles. In this lesson we learn how to use Jib's Maven and Gradle build plugins to configure and build images.
There is a tool by Google, called JIB (https://github.com/GoogleContainerTools/jib). JIB builds your Java application, containerizes it to a deployable image and pushes the image to a registry. It is fully configurable over Maven or Gradle.
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With