1、先要选取一个基板docker镜像,此处选用tomcat:8-jre8

2、通过基板镜像,build一个自有镜像:


Dockerfile:

FROM tomcat:8-jre8

MAINTAINER "Liu Li " 

ADD settings.xml /usr/local/tomcat/conf/
ADD tomcat-users.xml /usr/local/tomcat/conf/

settings.xml:



 

TomcatServer
admin
adm123
 

tomcat-users.xml:







这三个文件放在同一个文件夹里,然后在那个文件夹里执行:


 docker build -t my_tomcat:8-jre8 .

3、通过设定的自有镜像启动一个容器:


 docker run -d -p 8080:8080  my_tomcat:8-jre8

访问ip:8080可以获得tomcat的欢迎页

ip/manager可以获得tomcat的管理页面:登录用户名密码在上面文件中配置


4、maven管理的工程中的pom文件中:


注:如果pom中带s的复数标签已有,只需要将内容添加到标签下即可:

比如:

文件中已经存在plugins标签,往其中添加:


   
            
                xxxxxxxxxxxxxxxxxx  
                xxxxxxxxxxxxxxxxxx  
                xxxxxxxxxxx  
              
         .
         .
         .
              
                org.apache.maven.plugins  
                maven-compiler-plugin  
                3.1  
              
              
                org.apache.tomcat.maven  
                tomcat7-maven-plugin  
                2.2  
                
                    8080   
                    UTF-8
                    http://localhost:8080/manager/text  
                    admin  
                    adm123  
                    /${project.artifactId}  
                  
              


文件中存在properties标签时:


  
        .
        .
        .
        UTF-8  
        deploy  
        8.0.0-RC5  



文件中存在dependencies标签:


 
           
            xxxxxxxxxx  
            xxxxxxxxxxxx  
            xxxxxxxxxxxxx  
            xxxxxxxxxxxx  
         
        .
        .
        .
          
            org.apache.tomcat  
            tomcat-servlet-api  
            ${project.tomcat.version}  
            provided  
         
  



pom.xml:

localhost改成你部署的主机的ip

  
        UTF-8  
        deploy  
        8.0.0-RC5  
  
 
          
            org.apache.tomcat  
            tomcat-servlet-api  
            ${project.tomcat.version}  
            provided  
         
    
    
          
              
                org.apache.maven.plugins  
                maven-compiler-plugin  
                3.1  
              
              
                org.apache.tomcat.maven  
                tomcat7-maven-plugin  
                2.2  
                
                    8080   
                    UTF-8
                    http://localhost:8080/manager/text  
                    admin  
                    adm123  
                    /${project.artifactId}  
                  
              
          
    



5、完成之后,在项目工程文件夹中执行:


含义:构建并将工程部署到tomcat中,跳过单元测试。


mvn -Dmaven.test.skip=true tomcat7:deploy -e

结果如:


[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.drpeng:busimgnt:war:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ com.drpeng:busimgnt:[unknown-version], /root/work/OVERSEABOSS/modelBusisrv/busimgnt/pom.xml, line 97, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-install-plugin is missing. @ com.drpeng:busimgnt:[unknown-version], /root/work/OVERSEABOSS/modelBusisrv/busimgnt/pom.xml, line 77, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building busimgnt Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:deploy (default-cli) > package @ busimgnt >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ busimgnt ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 44 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ busimgnt ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 186 source files to /root/work/OVERSEABOSS/modelBusisrv/busimgnt/target/classes
[WARNING] /root/work/OVERSEABOSS/modelBusisrv/busimgnt/src/main/java/com/drpeng/busimgnt/api/SaleDomyBoxFileInfoResource.java:[9,42] warning: com.sun.org.apache.regexp.internal.RE is Sun proprietary API and may be removed in a future release
[WARNING] Note: Some input files use unchecked or unsafe operations.
[WARNING] Note: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ busimgnt ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ busimgnt ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ busimgnt ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ busimgnt ---
[INFO] Packaging webapp
[INFO] Assembling webapp [busimgnt] in [/root/work/OVERSEABOSS/modelBusisrv/busimgnt/target/busimgnt]
[INFO] Processing war project
[INFO] Copying webapp resources [/root/work/OVERSEABOSS/modelBusisrv/busimgnt/src/main/webapp]
[INFO] Webapp assembled in [324 msecs]
[INFO] Building war: /root/work/OVERSEABOSS/modelBusisrv/busimgnt/target/busimgnt.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-jar-plugin:2.3:jar (make-a-jar) @ busimgnt ---
[INFO] Building jar: /root/work/OVERSEABOSS/modelBusisrv/busimgnt/target/busimgnt-1.0-SNAPSHOT.jar
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) < package @ busimgnt <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ busimgnt ---
[INFO] Deploying war to http://localhost:8080/busimgnt  
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fbusimgnt
Uploaded: http://localhost:8080/manager/text/deploy?path=%2Fbusimgnt (18430 KB at 61229.1 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] OK - Deployed application at context path /busimgnt
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.720 s
[INFO] Finished at: 2016-11-16T10:10:31+08:00
[INFO] Final Memory: 30M/430M
[INFO] ------------------------------------------------------------------------



我的工程名字叫busimgnt,此时访问:

我的ip:8080/busimgnt,我的index中只写了hello world,因此访问后得到了该字符串,这时候,热部署就完成了,下次打包之后,执行本命令,就可以将新包热部署。