将springboot应用打入docker中运行的实现方法-创新互联

这几天研究了一下将spring boot应用打入到docker中运行,先前有一个maven插件,可以直接在src/main中建一个docker文件夹,新建一个Dockerfile文件,在进行编译打包之后,可以直接运行docker插件,相当于在对应的docker目录中执行 docker build .命令,会直接将当前应用打成镜像,然后运行,十分方便,但是在个人经过测试后发现,这个插件并不稳定,docker文件夹不一定每次都会打到target文件夹下,因此就会导致这个插件执行起来并没有多大用处。

我们提供的服务有:成都网站设计、网站制作、微信公众号开发、网站优化、网站认证、兴宁ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的兴宁网站制作公司

因此我在后来再将spring boot应用打成镜像的时候,不再使用提供的docker maven插件,而是单独在当前项目的根目录下新建一个Dockerfile文件,应用编写完了之后,直接手动执行命令将应用打成镜像,具体如下。

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中运行的实现方法-创新互联
网页路径:https://www.cdcxhl.com/article18/dicdgp.html

成都网站建设公司_创新互联,为您提供动态网站服务器托管搜索引擎优化App设计标签优化品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司