Introduction to Jib Jib is a library developed by Google that can directly build Docker and OCI images of Java applications. It is provided in the form of Maven and Gradle plug-ins. With Jib, Java developers can use the Java tools they are familiar with to build containers. Jib is a fast and simple container image building tool that takes care of all the steps required to package your application into a container image. It doesn't require you to write a Dockerfile or install Docker, and it integrates directly into Maven and Gradle - just add the plugin to your build and you can containerize your Java application instantly. Jib open source address: https://github.com/GoogleContainerTools/jib Common Docker build process Jib build process Jib Integration The project is Spring Cloud, version Hoxton.SR1. To integrate jib, you only need to add the jib plugin to pom. <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>${jib.version}</version> </plugin> Jib related complete configuration <properties> <!-- jib docker config--> <!-- jib version --> <jib.version>2.2.0</jib.version> <!-- Whether to skip jib packaging --> <jib.skip>true</jib.skip> <!-- Warehouse image name --> <jib.repository.name>akk-system</jib.repository.name> <!-- Startup Class --> <jib.main.class>com.akk.GatewayApplication</jib.main.class> <!-- Warehouse login username --> <REGISTRY_USERNAME>222222222222</REGISTRY_USERNAME> <!-- Warehouse login password --> <REGISTRY_PASSWORD>111111111111</REGISTRY_PASSWORD> </properties> <plugins> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>${jib.version}</version> <configuration> <skip>${jib.skip}</skip> <!-- Configure the base image --> <from> <image>openjdk:8-jre-alpine</image> </from> <!-- Configure push address, warehouse name, mirror name--> <to> <image>registry.cn-hangzhou.aliyuncs.com/akk_java/${jib.repository.name}</image> <tags> <!-- <tag>${jib.repository.name}</tag>--> <!-- <tag>${version}</tag>--> </tags> <auth> <username>${REGISTRY_USERNAME}</username> <password>${REGISTRY_PASSWORD}</password> </auth> </to> <!--Private servers are http instead of https. By default, jib does not push to non-https private servers. Private servers are added, but public servers are not added. --> <!-- <allowInsecureRegistries>true</allowInsecureRegistries>--> <container> <mainClass>${jib.main.class}</mainClass> <labels> <name>${artifactId}</name> </labels> </container> </configuration> <!--Bound to Maven lifecicle--> <!-- <executions>--> <!-- <execution>--> <!-- <phase>package</phase>--> <!-- <goals>--> <!-- <goal>build</goal>--> <!-- </goals>--> <!-- </execution>--> <!-- </executions>--> </plugin> </plugins> Parameter Description: At this point, you can see the jib plugin related content in the Maven menu of idea: For example: gateway module (need to package the image), the pom configuration is as follows <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>akk-system</artifactId> <groupId>com.akk</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>gateway</artifactId> <properties> <!-- jib docker config--> <jib.version>2.2.0</jib.version> <jib.skip>false</jib.skip> <jib.repository.name>akk-gateway</jib.repository.name> <jib.main.class>com.akk.GatewayApplication</jib.main.class> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> </dependency> </dependencies> </project> Common public dependency package pom (no need to package the image): <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>akk-system</artifactId> <groupId>com.akk</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>common</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <!-- jib docker config--> <jib.version>2.2.0</jib.version> <jib.skip>true</jib.skip> <jib.repository.name>akk-system</jib.repository.name> <jib.image.name>akk-system</jib.image.name> </properties> <dependencies> <!-- Dependency Information --> </dependencies> </project> Among them, properties covers the relevant parameter configuration of jib. Packaging image Run After packaging is complete, check the local docker image (the jib:dockerBuild command will not upload the image, but the jib:build command will upload the image) Pack and upload the image Run docker login --username=username --password=password registry.cn-hangzhou.aliyuncs.com Pull the image docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-gateway:latest Docker deployment project Microservice project deployment has many modules and is generally a distributed cluster environment, so manual deployment is cumbersome. You can use automated deployment tools like Jenkins. After using Jenkins to package and upload the image, log in to the remote server and execute the script to start it. like: #!/bin/bash # Log in to the docker repositorydocker login --username=username --password=password registry.cn-hangzhou.aliyuncs.com # Stop the running container docker ps | grep akk_java | awk '{print $1}' | xargs docker stop # Delete the container docker ps -a -q | grep akk_java | awk '{print $1}' | xargs docker rm # Query the image file and delete docker images | grep akk_java | awk '{print $3}' | xargs docker rmi # Pull the image docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-user:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-gateway:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-task:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-store:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-pay:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-app-api:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-sso-auth:latest docker pull registry.cn-hangzhou.aliyuncs.com/akk_java/akk-seata:latest After re-pulling the image, execute the This concludes this article about the detailed steps of using jib for docker deployment in Spring Cloud. For more relevant Spring Cloud docker deployment content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The whole process record of vue3 recursive component encapsulation
>>: Detailed explanation of the lock structure in MySQL
Table of contents User Management Create a new us...
The span tag is often used when making HTML web p...
This article example shares the specific code of ...
Table of contents Vue custom directive Custom dir...
Install ssh tool 1. Open the terminal and type th...
1. Install Baidu Eslint Rule plugin npm i -D esli...
Ubuntu 16.04 installs the PHP7.0 environment by d...
Author: Ding Yi Source: https://chengxuzhixin.com...
System environment: Win10 64-bit MySQL version: m...
1. Download related tools and images Download Lin...
This article shares the specific code for JavaScr...
Click here to return to the 123WORDPRESS.COM HTML ...
I used the label tag when I was doing something re...
Table of contents 1. Panorama II. Background 1. R...
This article example shares the specific code for...