maven docker push harbor

maven docker push harbor
docker-maven-plugin

一.在m2 setting.xml的servers节点增加一个server节点

<server>
      <!--maven的pom中可以根据这个id找到这个server节点的配置-->  
      <id>docker-harbor</id>
      <username>your username</username>
      <password>your passwd</password>
      <configuration>
            <email>your email</email>
      </configuration>
    </server>

二.在环境变量增加
DOCKER_HOST:tcp://172.16.9.6:2375
如果本机没有docker daemon环境,找一台已经部署了docker并打开api remote接口设置。
参考 https://www.cnblogs.com/520playboy/p/7921633.html

三.在你的maven项目新建 src/main/docker/Dockerfile 如图
在这里插入图片描述
FROM tomcat:8
COPY crms.war /usr/local/tomcat/webapps/app.war
CMD [“catalina.sh”, “run”]

四:在pom.xml的properties节点增加
<docker.image.prefix>chezhibao</docker.image.prefix>
<docker.repostory>harbor.mychebao.com</docker.repostory>
<docker.registry.name>cicd</docker.registry.name>

五:在pom.xml的build节点增加

 <build>
        <finalName>crms</finalName>
        <plugins>
            <!-- war plugin config: 对静态资源进行过滤,替换变量。 如果你不需要,请移除这一段 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>${project.artifactId}</warName>
                    <packagingExcludes>
                    </packagingExcludes>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/*.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
              <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.4.13</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.registry.name}/${project.artifactId}:${project.version}</image>
                                <newName>${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}</newName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>push-image</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>push</goal>
                            </goals>
                            <configuration>
                                <imageName>${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}</imageName>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <serverId>docker-harbor</serverId>
                        <registryUrl>${docker.repostory}</registryUrl>
                        <forceTags>true</forceTags>
                        <pushImage>true</pushImage>
                        <dockerDirectory>src/main/docker</dockerDirectory>
                        <imageName>
                            ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
                        </imageName>
                        <imageTags>
                            <imageTag>${project.version}</imageTag>
                        </imageTags>
                        <resources>
                            <rescource>
                                <targetPath></targetPath>
                                <directory>target/</directory>
                                <include>${project.build.finalName}.war</include>
                            </rescource>
                        </resources>
                    </configuration>
                </plugin>
            </plugins>
    </build>

六.看一下结果
在这里插入图片描述

在这里插入图片描述

七.docker pull harbor.****.com/cicd/crms:CRED-499-SNAPSHOT

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值