Java的新项目学成在线笔记-day20(八)

3.2.7 停止与删除 
要删除的一个镜像重新创建,需要通过如下步骤:
1、停止正在运行的容器 docker stop 容器名
例如:docker stop xc-govern-center-test 2、删除容器
docker rm 容器名 例如:docker rm xc-govern-center-test 3、删除镜像
docker rmi 镜像名或镜像Id 例如:docker rmi xc-govern-center:1.0-SNAPSHOT
  3.2.8 maven构建镜像 
上边构建的过程是通过手工一步一步完成,maven提供docker-maven-plugin插件可完成从打包到构建镜像、构建 容器等过程。
1、编写pom_docker.xml
 

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<?xml version="1.0" encoding="UTF‐8"?> <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

[url]http://maven.apache.org/xsd/maven[/url]‐4.0.0.xsd">  

 <parent>    

   <artifactId>xc‐framework‐parent</artifactId>   

    <groupId>com.xuecheng</groupId>    

   <version>1.0‐SNAPSHOT</version> 

      <relativePath>../xc‐framework‐parent/pom.xml</relativePath>  

 </parent> 

  <modelVersion>4.0.0</modelVersion> 

    <artifactId>xc‐govern‐center</artifactId>

   <version>1.0‐SNAPSHOT</version>  

 <dependencies>   

    <!‐‐ 导入Eureka服务的依赖 ‐‐>    

   <dependency>     

      <groupId>org.springframework.cloud</groupId>

           <artifactId>spring‐cloud‐starter‐netflix‐eureka‐server</artifactId>  

     </dependency>

   </dependencies>  

 <build>     

  <finalName>${project.artifactId}‐${project.version}</finalName> 

      <plugins>     

      <plugin>           

    <groupId>org.springframework.boot</groupId>   

           <artifactId>spring‐boot‐maven‐plugin</artifactId>     

      </plugin>

 

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

<plugin>     

           <groupId>com.spotify</groupId>      

          <artifactId>docker‐maven‐plugin</artifactId>   

             <version>1.0.0</version>        

        <!‐‐docker镜像相关的配置信息‐‐>          

      <configuration>                

    <!‐‐镜像名,这里用工程名‐‐>     

               <imageName>${project.artifactId}‐${project.version}</imageName>         

           <!‐‐Dockerfile文件所在目录‐‐>         

           <dockerDirectory>${project.basedir}/src/main/resources</dockerDirectory>         

           <!‐‐TAG,这里用工程版本号‐‐>          

          <imageTags>                 

       <imageTag>${project.version}</imageTag>  

                  </imageTags>       

             <imageName>${project.artifactId}:${project.version}</imageName>      

              <!‐‐构建镜像的配置信息‐‐>        

            <resources>                  

      <resource>                 

           <targetPath>/</targetPath>      

                      <directory>${project.build.directory}</directory>       

                     <include>${project.artifactId}‐${project.version}.jar</include>                 

       </resource>             

       </resources>             

   </configuration>  

          </plugin>      

  </plugins>   

 </build> </project>


2、将Dockerfile文件拷贝到src/main/resource下
3、删除之前创建的xc-govern-center镜像 4、进入工程根目录(pom_docker.xml所在目录)执行
 

[AppleScript] 纯文本查看 复制代码

?

1

mvn ‐f pom_docker.xml clean package ‐DskipTests docker:build


创建镜像成功,结果如下:
 

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

Successfully built 64682c9ba311

 [INFO] Built xc‐govern‐center:1.0‐SNAPSHOT

 [INFO] Tagging xc‐govern‐center:1.0‐SNAPSHOT with 1.0‐SNAPSHOT [INFO] ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐[INFO] BUILD SUCCESS [INFO] ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

[INFO] Total time: 7.409 s [INFO] Finished at: 20180719T14:21:16+08:00 [INFO] Final Memory: 52M/414M [INFO] ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

 

你可能感兴趣的:(JAVA)