打包war
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.manager</groupId>
<artifactId>test.manager</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>war</packaging>
<name>test.manager</name>
<description/>
<properties>
<webVersion>2.5</webVersion>
<servlet.version>3.1.0</servlet.version>
<jsp.version>2.2</jsp.version>
<jstl.version>1.2.5</jstl.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<docker.repostory>10.0.2.4:5000</docker.repostory>
<docker.dockerhost>http://10.0.2.4:5000</docker.dockerhost>
<docker.registry.name>hnzyst</docker.registry.name>
<docker.artifactId>ddc.manager</docker.artifactId>
<!-- 指定docker image 的版本号 -->
<docker.version>1.0.0</docker.version>
<docker.active>test</docker.active>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<outputDirectory>${basedir}/WebRoot/WEB-INF/classes</outputDirectory>
<resources>
<!--指定xml文件位置-->
<resource>
<directory>${basedir}/src</directory>
<includes>
<include> *.xml</include>
<include> *.properties</include>
<include> com/aj/**/config/*.xml</include>
<include> com/aj/**/**/config/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/docker/${docker.active}</directory>
<includes>
<include>remote.xml</include>
<include>processors.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>WebRoot/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<!--配置本地jar包在项目中的存放路径-->
<directory>${basedir}/WebRoot/</directory>
<!--配置打包时jar包的存放路径-->
<targetPath>/</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<!-- 打包Docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<id>build-image</id>
<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}/${docker.active}/${docker.artifactId}:${docker.version}</image>
<newName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}:${docker.version}</newName>
</configuration>
</execution>
<execution>
<id>push-image</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<imageName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}:${docker.version}</imageName>
</configuration>
</execution>
</executions>
<configuration>
<serverId>docker-local</serverId>
<registryUrl>${docker.dockerhost}</registryUrl>
<pushImage>true</pushImage>
<dockerDirectory>${project.basedir}/docker/build</dockerDirectory>
<imageName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}</imageName>
<imageTags>
<imageTag>${docker.version}</imageTag>
</imageTags>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${basedir}/target/</directory>
<include>test.manager.war</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
<finalName>test.manager</finalName>
</build>
</project>
运行打包
mvn clean install -Ddocker.version=1.0.0. -Ddocker.active=test
启动命名
#!/bin/bash
docker rm -f test.manager
docker run -d -p 8090:8080 --network mynet --link fjdcgl.server --name test.manager 10.0.2.4:5000/hnzyst/test/test.manager