一 介绍
使用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

版权声明:本文为chengqiuming原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/chengqiuming/article/details/80956569