將springboot應用打入docker中運行的實現(xiàn)方法-創(chuàng)新互聯(lián)

這幾天研究了一下將spring boot應用打入到docker中運行,先前有一個maven插件,可以直接在src/main中建一個docker文件夾,新建一個Dockerfile文件,在進行編譯打包之后,可以直接運行docker插件,相當于在對應的docker目錄中執(zhí)行 docker build .命令,會直接將當前應用打成鏡像,然后運行,十分方便,但是在個人經(jīng)過測試后發(fā)現(xiàn),這個插件并不穩(wěn)定,docker文件夾不一定每次都會打到target文件夾下,因此就會導致這個插件執(zhí)行起來并沒有多大用處。

我們提供的服務有:成都網(wǎng)站設計、網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、興寧ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的興寧網(wǎng)站制作公司

因此我在后來再將spring boot應用打成鏡像的時候,不再使用提供的docker maven插件,而是單獨在當前項目的根目錄下新建一個Dockerfile文件,應用編寫完了之后,直接手動執(zhí)行命令將應用打成鏡像,具體如下。

springboot應用

pom.xml

在這里的pom.xml中需要指定幾個倉庫,以及提供幾個插件,具體如下:

<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>

 <groupId>cn.com</groupId>
 <artifactId>springbootweb</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>spring :: boot :: web</name>

 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.1.RELEASE</version>
  <relativePath/>
 </parent>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <docker.image.prefix>springio</docker.image.prefix>
  <docker.version>0.3.8</docker.version>
  <java.version>1.8</java.version>
 </properties>

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



 <repositories>
  <repository>
   <id>spring-snapshots</id>
   <url>http://repo.spring.io/snapshot</url>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </repository>
  <repository>
   <id>spring-milestones</id>
   <url>http://repo.spring.io/milestone</url>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </repository>
 </repositories>

 <pluginRepositories>
  <pluginRepository>
   <id>spring-snapshots</id>
   <url>http://repo.spring.io/snapshot</url>
  </pluginRepository>
  <pluginRepository>
   <id>spring-milestones</id>
   <url>http://repo.spring.io/milestone</url>
  </pluginRepository>
 </pluginRepositories>


 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
     <compilerArgument>-parameters</compilerArgument>
     <source>1.8</source>
     <target>1.8</target>
     <encoding>UTF-8</encoding>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
     <skipTests>true</skipTests>
    </configuration>
   </plugin>

   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <configuration>
     <encoding>UTF-8</encoding>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <!--<version>${spring.boot.version}</version>-->
    <configuration>
     <mainClass>cn.com.SpringBootWebApplication</mainClass>
     <layout>ZIP</layout>
    </configuration>
    <executions>
     <execution>
      <goals>
       <goal>
        repackage
       </goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

 <profiles>
  <profile>
   <id>JDK1.8</id>
   <activation>
    <activeByDefault>true</activeByDefault>
   </activation>
   <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>
   </properties>
  </profile>
 </profiles>
</project>

當前標題:將springboot應用打入docker中運行的實現(xiàn)方法-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://bm7419.com/article18/dicdgp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、服務器托管、搜索引擎優(yōu)化App設計、標簽優(yōu)化品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司