鏡像管理以Jib爲例git
在pom.xml中添加以下打包插件github
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<from>
<image>openjdk:alpine</image>
</from>
<to>
<image>localhost:5000/my-image:built-with-jib</image>
<credHelper>osxkeychain</credHelper>
<tags>
<tag>tag2</tag>
<tag>latest</tag>
</tags>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xmy:flag=jib-rules</jvmFlag>
</jvmFlags>
<mainClass>mypackage.MyApp</mainClass>
<args>
<arg>some</arg>
<arg>args</arg>
</args>
<ports>
<port>1000</port>
<port>2000-2003/udp</port>
</ports>
<labels>
<key1>value1</key1>
<key2>value2</key2>
</labels>
<format>OCI</format>
</container>
</configuration>
</plugin>
複製代碼
在pom.xml中添加以下打包插件web
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<from>
<image>openjdk:alpine</image>
</from>
<to>
<image>localhost:5000/my-image:built-with-jib</image>
<tags>
<tag>tag2</tag>
<tag>latest</tag>
</tags>
</to>
<container>
<appRoot>/usr/local/tomcat/webapps/ROOT</appRoot>
</container>
</configuration>
</plugin>
複製代碼
注意:1. 以上兩種狀況推薦添加<tag>latest</tag>
,這樣更新鏡像的時候不用指定版本就能夠獲取最新的鏡像了docker
jib:build
到package
把mvn compile jib:build
綁定到mvn package
tomcat
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
...
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
複製代碼
執行mvn package
就會建立鏡像並把鏡像上傳至鏡像倉庫bash
docker pull 鏡像
複製代碼
docker run -p 端口:8080 -d --name 實例化的容器名稱 鏡像名稱
複製代碼
-p: 把容器的8080端口映射到本機的某個端口 -d: 後臺運行,不在console打印日誌 --name: 爲實例化的容器指定名稱app
腳本webapp
docker pull 鏡像
docker run -p 端口:8080 -d --name 實例化的容器名稱 鏡像名稱
複製代碼
參考:jvm