How to use the jib plug-in to build an image of a Java application
Introduction
Containerization of Java application development requires the production of docker images. If the user does not have docker installed locally, he can use jib to create a tar file with an image.
Jib provides four ways to use:
Maven plug-in: jib-maven-plugin
Gradle plug-in: jib -gradle-plugin
Java library: Jlib Core
Jib CLI
jib build tool It mainly contains four powerful functions.
build: Provides the function of creating an image and pushing it to a remote warehouse.
buildTar: Provides the function of creating a tar file containing an image.
dockerBuild: Provides the function of creating a docker image locally.
exportDocker: rContext provides the function of creating dockerfile.
When compiling and building without a docker environment, you cannot use the build command and dockerBuild command to create an image. You can only use the buildTar command to create a tar file containing the image. .
Use the Maven plug-in to build Java applications as docker images
1. Modify the project code that needs to be mirrored: find the pom file to declare the jib plug-in, and
declare the Jib plug-in in the pom.xml file :
<!--使用jib插件--> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>1.3.0</version> <configuration> <!--from节点用来设置镜像的基础镜像,相当于Docerkfile中的FROM关键字--> <from> <!--使用openjdk官方镜像,tag是8-jdk-stretch,表示镜像的操作系统是debian9,装好了jdk8--> <image>openjdk:8-jdk-stretch</image> </from> <to> <!--镜像名称和tag,使用了mvn内置变量${project.version},表示当前工程的version--> <image>lendea/hellojib:${project.version}</image> </to> <!--容器相关的属性--> <container> <!--jvm内存参数--> <jvmFlags> <jvmFlag>-Xms256m</jvmFlag> <jvmFlag>-Xmx256m</jvmFlag> </jvmFlags> <!--要暴露的端口--> <ports> <port>8081</port> </ports> </container> </configuration> </plugin>
from tag: Set the base image, which is equivalent to the FROM keyword in the dockerfile. It is recommended to use the image in SWR. The download speed is fast and stable during construction.
to tag: Set the image name and tag of the created image.
container tag: Set container-related properties, jvm memory parameters, ports, etc.
2. Create a build task and execute it
# -Dmaven.test.skip=true: 跳过单元测试 # -U: 每次构建检查以来更新,可避免缓存中快照版本依赖不更新问题,但会牺牲部分性能 # -e -X: 打印调试信息,定位疑难构建问题时建议使用此参数构建 # -B: 以batch模式运行,可避免日志打印出现ArrayIndexOutOfBoundsException异常 mvn compile jib:buildTar -Dmaven.test.skip=true -U -e -X -B
In the target directory of the java project, you can see the generated tar image.
3. Use tar image
Execute the docker load -i xxx.tar
command to load the tar file image into the local image warehouse, and then use docker run --rm -p 8081:8081 lendea/hellojib:0.0.1
and other commands start the container to test the function.
The above is the detailed content of How to use the jib plug-in to build an image of a Java application. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is
