最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

最簡(jiǎn)單的spring boot打包docker鏡像的實(shí)現(xiàn)

 更新時(shí)間:2020年10月22日 11:48:37   作者:第五羽火  
這篇文章主要介紹了最簡(jiǎn)單的spring boot打包docker鏡像的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

這個(gè)spring boot項(xiàng)目只在網(wǎng)頁(yè)輸出一個(gè)hello world文本,沒(méi)有其他復(fù)雜的配置和頁(yè)面,屬于入門級(jí),可以放心食用。

本項(xiàng)目通過(guò)maven打包,打包和構(gòu)建鏡像的命令為:

mvn clean install package docker:build

spring boot打包docker鏡像步驟如下:

(一)

在pom.xml文件中添加docker配置:

<!--docker maven plugin,在目錄src/main/docker下創(chuàng)建Dockerfile文件,Dockerfile文件用來(lái)說(shuō)明如何構(gòu)建按鏡像-->
<plugin>
 <groupId>com.spotify</groupId>
 <artifactId>docker-maven-plugin</artifactId>
 <version>0.4.13</version>
 <configuration>
 <imageName>${project.artifactId}</imageName>
 <dockerDirectory>src/main/docker</dockerDirectory>
 <resources>
  <resource>
  <targetPath>/</targetPath>
  <directory>${project.build.directory}</directory>
<!--下面的.jar不要忘記寫,否則會(huì)報(bào)“ Exception caught: ADD failed: stat /var/lib/docker/tmp/docker-builder646478477/yang-0.0.1.jar: no such file or directory”錯(cuò)誤-->
  <include>${project.build.finalName}.jar</include>
  </resource>
 </resources>
 </configuration>
</plugin>

(二)

在src/main/docker文件夾(新建文件夾)下建Dockerfile文件,該文件不要后綴,可以新建一個(gè)txt文件,再把.txt后綴去掉,文件內(nèi)容如下:

From java:8
VOLUME /TMP
ADD yang-0.0.1.jar /yang-0.0.1.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/yang.jar"]

ADD yang-0.0.1.jar /yang-0.0.1.jar的名字 要和pom的<artifactId>yang</artifactId>

保持名字一樣,不然maven打出來(lái)的包,docker找不到。

比如,我這個(gè)項(xiàng)目中的<artifactId>標(biāo)簽內(nèi)容為:

pom.xml文件:

<artifactId>yang</artifactId>
<version>0.0.1</version>
<name>yang</name>
<packaging>jar</packaging>

Dockerfile文件:

ADD yang-0.0.1.jar /yang-0.0.1.jar

ADD yang-0.0.1.jar /yang-0.0.1.jar這一句前面的jar包是本地打包的jar包名稱,后面是復(fù)制到docker后的重命名。

本項(xiàng)目完整的pom.xml文件內(nèi)容如下,各位可以作為參考:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.2.4.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.springboot</groupId>
 <artifactId>yang</artifactId>
 <version>0.0.1</version>
 <name>yang</name>
 <packaging>jar</packaging>
 <description>Demo project for Spring Boot</description>

 <properties>
 <java.version>1.8</java.version>
 <!--<docker.image.prefix>yang-0.0.1</docker.image.prefix>-->
 </properties>

 <dependencies>
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
 </dependency>

 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <scope>runtime</scope>
  <optional>true</optional>
 </dependency>
 <dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <optional>true</optional>
 </dependency>
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
  <exclusions>
  <exclusion>
   <groupId>org.junit.vintage</groupId>
   <artifactId>junit-vintage-engine</artifactId>
  </exclusion>
  </exclusions>
 </dependency>
 <!--redis-->
 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-redis -->
 <!--<dependency>-->
  <!--<groupId>org.springframework.boot</groupId>-->
  <!--<artifactId>spring-boot-starter-redis</artifactId>-->
  <!--<version>1.4.7.RELEASE</version>-->
 <!--</dependency>-->
 <!--&lt;!&ndash; https://mvnrepository.com/artifact/mysql/mysql-connector-java &ndash;&gt;-->
 <!--<dependency>-->
  <!--<groupId>mysql</groupId>-->
  <!--<artifactId>mysql-connector-java</artifactId>-->
  <!--<version>8.0.18</version>-->
 <!--</dependency>-->

 </dependencies>

 <build>
 <plugins>
  <plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  </plugin>
  <!--docker maven plugin,在目錄src/main/docker下創(chuàng)建Dockerfile文件,Dockerfile文件用來(lái)說(shuō)明如何構(gòu)建按鏡像-->
  <plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.4.13</version>
  <configuration>
   <!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName>-->
   <imageName>${project.artifactId}</imageName>
   <dockerDirectory>src/main/docker</dockerDirectory>
   <resources>
   <resource>
    <targetPath>/</targetPath>
    <directory>${project.build.directory}</directory>
    <include>${project.build.finalName}.jar</include>
   </resource>
   </resources>
  </configuration>
  </plugin>
 </plugins>
 </build>

</project>

到此這篇關(guān)于最簡(jiǎn)單的spring boot打包docker鏡像的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)spring boot打包docker鏡像內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • rocketmq client 日志的問(wèn)題處理方式

    rocketmq client 日志的問(wèn)題處理方式

    這篇文章主要介紹了rocketmq client 日志的問(wèn)題處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • 淺析Spring IOC bean為什么默認(rèn)是單例

    淺析Spring IOC bean為什么默認(rèn)是單例

    單例的意思就是說(shuō)在 Spring IoC 容器中只會(huì)存在一個(gè) bean 的實(shí)例,無(wú)論一次調(diào)用還是多次調(diào)用,始終指向的都是同一個(gè) bean 對(duì)象,本文小編將和大家一起分析Spring IOC bean為什么默認(rèn)是單例,需要的朋友可以參考下
    2023-12-12
  • 深入理解Java設(shè)計(jì)模式之外觀模式

    深入理解Java設(shè)計(jì)模式之外觀模式

    這篇文章主要介紹了JAVA設(shè)計(jì)模式之外觀模式的的相關(guān)資料,文中示例代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解下
    2021-11-11
  • Spring事務(wù)中@Transactional注解不生效的原因分析與解決

    Spring事務(wù)中@Transactional注解不生效的原因分析與解決

    在Spring框架中,@Transactional注解是管理數(shù)據(jù)庫(kù)事務(wù)的核心方式,本文將深入分析事務(wù)自調(diào)用的底層原理,解釋為什么事務(wù)不生效,并提供多種解決方案,希望對(duì)大家有所幫助
    2025-03-03
  • crawler4j抓取頁(yè)面使用jsoup解析html時(shí)的解決方法

    crawler4j抓取頁(yè)面使用jsoup解析html時(shí)的解決方法

    crawler4j對(duì)response沒(méi)有指定編碼的頁(yè)面,解析成亂碼,很讓人煩惱,下面給出解決方法,需要的朋友可以參考下
    2014-04-04
  • RocketMQ根據(jù)Tag進(jìn)行消息過(guò)濾

    RocketMQ根據(jù)Tag進(jìn)行消息過(guò)濾

    消費(fèi)者訂閱了某個(gè)主題后,Apache RocketMQ 會(huì)將該主題中的所有消息投遞給消費(fèi)者。若消費(fèi)者只需要關(guān)注部分消息,可通過(guò)設(shè)置過(guò)濾條件在 Apache RocketMQ 服務(wù)端進(jìn)行過(guò)濾,只獲取到需要關(guān)注的消息子集,避免接收到大量無(wú)效的消息
    2023-02-02
  • @RequestBody獲取不到參數(shù)的問(wèn)題

    @RequestBody獲取不到參數(shù)的問(wèn)題

    這篇文章主要介紹了@RequestBody獲取不到參數(shù)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • SpringData關(guān)鍵字查詢實(shí)現(xiàn)方法詳解

    SpringData關(guān)鍵字查詢實(shí)現(xiàn)方法詳解

    這篇文章主要介紹了SpringData關(guān)鍵字查詢實(shí)現(xiàn)方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • java項(xiàng)目中classpath指向哪里

    java項(xiàng)目中classpath指向哪里

    這篇文章介紹了java項(xiàng)目中classpath指向哪里及工作原理,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • Java方法重載的使用實(shí)戰(zhàn)案例

    Java方法重載的使用實(shí)戰(zhàn)案例

    這篇文章主要介紹了Java方法重載的使用,結(jié)合具體實(shí)例形式分析了java方法重載的基本使用技巧與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-09-09

最新評(píng)論

泾源县| 平南县| 阜城县| 芦溪县| 武隆县| 卢湾区| 驻马店市| 甘德县| 阜新| 延庆县| 时尚| 广西| 宜宾县| 丘北县| 穆棱市| 五寨县| 乐亭县| 伊宁市| 石泉县| 诸城市| 葫芦岛市| 竹溪县| 靖安县| 闸北区| 白河县| 宜春市| 宝坻区| 米泉市| 郸城县| 长岭县| 涟水县| 高尔夫| 景德镇市| 若尔盖县| 台山市| 大庆市| 镇安县| 多伦县| 龙川县| 辽源市| 渝北区|