Maven的Docker插件推动镜像到Docker Hub

353 篇文章 25 订阅
84 篇文章 5 订阅
一 介绍
使用docker push命令可以实现镜像的推送,也可使用Maven插件推送镜像。
二 修改Maven的全局配置文件settings.xml
  <servers>
    <server>
      <id>docker-hub</id>
      <username>cakin24</username>
      <password>cakin24的密码</password>
      <configuration>
          <email>DockerHub邮箱</email>
      </configuration>
    </server>
  </servers>
三 修改pom.xml
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.13</version>
        <configuration>
          <imageName>cakin24/microservice-discovery-eureka:0.0.4</imageName>
          <baseImage>java</baseImage>
          <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}.jar</include>
            </resource>
          </resources>

          <!-- 与maven配置文件settings.xml中配置的server.id一致,用于推送镜像 -->
          <serverId>docker-hub</serverId>
        </configuration>
      </plugin>
    </plugins>
如上,添加ServerId段落,并引用settings.xml中的server的id即可。
四 执行以下命令,添加pushImage的标识,表示推送镜像
[root@master microservice-discovery-eureka]# mvn clean package docker:build -DpushImage
[INFO] Scanning for projects...
[INFO]
[INFO] -----------< com.itmuch.cloud:microservice-discovery-eureka >-----------
[INFO] Building microservice-discovery-eureka 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ microservice-discovery-eureka ---
[INFO] Deleting /home/springcloud/microservice-discovery-eureka/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ microservice-discovery-eureka ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ microservice-discovery-eureka ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/springcloud/microservice-discovery-eureka/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ microservice-discovery-eureka ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/springcloud/microservice-discovery-eureka/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ microservice-discovery-eureka ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ microservice-discovery-eureka ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ microservice-discovery-eureka ---
[INFO] Building jar: /home/springcloud/microservice-discovery-eureka/target/microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ microservice-discovery-eureka ---
[INFO]
[INFO] --- docker-maven-plugin:0.4.13:build (default-cli) @ microservice-discovery-eureka ---
[INFO] Copying /home/springcloud/microservice-discovery-eureka/target/microservice-discovery-eureka-0.0.1-SNAPSHOT.jar -> /home/springcloud/microservice-discovery-eureka/target/docker/microservice-discovery-eureka-0.0.1-SNAPSHOT.jar
[INFO] Building image cakin24/microservice-discovery-eureka:0.0.4
Step 1/3 : FROM java

---> d23bdf5b1b1b
Step 2/3 : ADD /microservice-discovery-eureka-0.0.1-SNAPSHOT.jar //

---> d7d9fd5f6945
Step 3/3 : ENTRYPOINT ["java", "-jar", "/microservice-discovery-eureka-0.0.1-SNAPSHOT.jar"]

---> Running in ec6736f940a4
Removing intermediate container ec6736f940a4
---> f5072d37cf1e
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built f5072d37cf1e
Successfully tagged cakin24/microservice-discovery-eureka:0.0.4
[INFO] Built cakin24/microservice-discovery-eureka:0.0.4
[INFO] Pushing cakin24/microservice-discovery-eureka:0.0.4
The push refers to repository [docker.io/cakin24/microservice-discovery-eureka]
c86e8d848087: Pushed
35c20f26d188: Mounted from cakin24/microservice-discovery-eureka-0.0.1
c3fe59dd9556: Mounted from cakin24/microservice-discovery-eureka-0.0.1
6ed1a81ba5b6: Mounted from cakin24/microservice-discovery-eureka-0.0.1
a3483ce177ce: Mounted from cakin24/microservice-discovery-eureka-0.0.1
ce6c8756685b: Mounted from cakin24/microservice-discovery-eureka-0.0.1
30339f20ced0: Mounted from cakin24/microservice-discovery-eureka-0.0.1
0eb22bfb707d: Mounted from cakin24/microservice-discovery-eureka-0.0.1
a2ae92ffcd29: Mounted from cakin24/microservice-discovery-eureka-0.0.1
0.0.4: digest: sha256:b1a1ef36db76cc29f8bb73f27d7022017ba27a62a7363a3a3695ca458f1ec7a1 size: 2212
null: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:41 min
[INFO] Finished at: 2018-07-07T20:50:35+08:00
[INFO] ------------------------------------------------------------------------
五 测试
[root@master microservice-discovery-eureka]# docker images
REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
cakin24/microservice-discovery-eureka         0.0.4               f5072d37cf1e        10 minutes ago      685MB



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值