---
# System prepended metadata

title: jib image package
tags: [MAVEN, JIB]

---


# jib image package

###### tags: `JIB`,`MAVEN`

mainClass: if project has more main() method, assign the springboot initializer method

cmd
---

1. local build(to docker daemon)
mvn compile jib:dockerBuild

2. 推送到遠程(登入到Dockerhub)
mvn compile jib:build
mvn clean install jib:build //重新包

---

```
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.1.0</version>
			</plugin>
			<plugin>
				<groupId>com.google.cloud.tools</groupId>
				<artifactId>jib-maven-plugin</artifactId>
				<version>1.3.0</version>
				<configuration>
					<!--from設定image所需要的基礎image 相當于Docerkfile中的FROM关键字 -->
					<from>
						<!--base image -->
						<image>openjdk:8-jdk-stretch</image>
					</from>
					<to>
						<!--image名稱和tag，使用了mvn内置變數${project.version}，表示當前的version -->
						<image>registry.hub.docker.com/monktaiwan/poi_tl_demo:${project.version}</image>
					</to>
					<!--容器相關的属性 -->
					<container>
						<!--要暴露的端口 -->
						<ports>
							<port>8080</port>
						</ports>
						<!--使用容器時間系統時間匹配 -->
						<useCurrentTimestamp>true</useCurrentTimestamp>
						<mainClass>com.example.springbootdocker.SpringBootDockerApplication</mainClass>
					</container>
				</configuration>
			</plugin>
```


ref:
[link text](https://b0444135.medium.com/jib%E6%89%93%E5%8C%85spring-boot-40d33dc59ebe)

    
    
