关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回

怎么把spring boot应用发布到Harbor

发布时间:2022-09-27 11:06:32

小编给大家分享一下怎么把spring boot应用发布到Harbor,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

settings.xml配置

<server>
   <id>docker-hub</id>
   <username>admin</username>
   <password>Harbor12345</password>
  </server>

pom.xml配置

</parent>
    <groupId>com.topcheer</groupId>
    <artifactId>docker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>docker</name>
    <description>Demo project for Spring Boot</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <docker.image.prefix>topcheer</docker.image.prefix>
    <docker.repostory>192.168.180.105:1180</docker.repostory>
  </properties>

  <dependencies>
  

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
  <repositories>
    <repository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
    </repository>
  </repositories>
  

   <build>
    <finalName>docker</finalName>
    <plugins>
      <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
      <!--加入下面两项配置-->
      <executions>
       <execution>
        <goals>
         <goal>repackage</goal>
        </goals>
       </execution>
      </executions>
      <configuration>
         <includeSystemScope>true</includeSystemScope>
      </configuration>
   </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>1.2.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
          <execution>
            <id>tag-image</id>
            <phase>package</phase>
            <goals>
              <goal>tag</goal>
            </goals>
            <configuration>
              <image>${docker.repostory}/${docker.image.prefix}/${project.artifactId}:1.0.1</image>
              <newName>${docker.repostory}/${docker.image.prefix}/${project.artifactId}:1.0.1</newName>
            </configuration>
          </execution>
          <execution>
            <id>push-image</id>
            <phase>deploy</phase>
            <goals>
              <goal>push</goal>
            </goals>
            <configuration>
              <imageName>${docker.repostory}/${docker.image.prefix}/${project.artifactId}:1.0.1</imageName>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <serverId>docker-hub</serverId>
          <registryUrl>${docker.repostory}</registryUrl>
          <dockerHost>http://192.168.180.105:2375</dockerHost>
          <forceTags>true</forceTags>
          <pushImage>true</pushImage>
          <dockerDirectory>src/main/docker</dockerDirectory>
          <imageName>${docker.repostory}/${docker.image.prefix}/${project.artifactId}:1.0.1</imageName>
          <imageTags>
            <imageTag>1.0.2</imageTag>
          </imageTags>
          <resources>
            <rescource>
              <targetPath></targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}.jar</include>
            </rescource>
          </resources>
          <includeSystemScope>true</includeSystemScope>
        </configuration>
      </plugin>
    </plugins>
  </build>

运行命令

clean package docker:build -DpushImage -Dmaven.test.skip=true

怎么把spring boot应用发布到Harbor

看完了这篇文章,相信你对“怎么把spring boot应用发布到Harbor”有了一定的了解,如果想了解更多相关知识,欢迎关注风纳云行业资讯频道,感谢各位的阅读!

另外有需要云服务器可以了解下风纳云fengnayun.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


/template/Home/Dawn/PC/Static

选择风纳云,也许是您成就一番大事业的开端

注册账号