Maven + Docker

一、设置POM.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<build>
  <finalName>ROOT</finalName>
  <plugins>
   <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>
    </executions>
    <configuration>
     <dockerDirectory>${project.basedir}/docker</dockerDirectory>
     <imageName>${project.artifactId}:${project.version}</imageName>
     <imageTags>
      <imageTag>latest</imageTag>
     </imageTags>
     <resources>
          <resource>
            <targetPath>/</targetPath>
            <directory>${project.build.directory}</directory>
            <include>ROOT.war</include>
          </resource>
        </resources>
    </configuration>
   </plugin>
  </plugins>
 </build>

二、在工程下创建一个docker目录

 

三、在docker目录下创建文件Dockerfile,如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FROM java:7
MAINTAINER kingsy <kingsylin@vip.qq.com>
ENV TOMCAT_VERSION apache-tomcat-7.0.75
ADD ${TOMCAT_VERSION}.tar.gz /
WORKDIR /${TOMCAT_VERSION}
# INSTALL TOMCAT
RUN rm -rf webapps/*
# Add WAR
ADD ROOT.war webapps/
# RUN
CMD ["./bin/catalina.sh", "run"]
EXPOSE 80
EXPOSE 443

Leave a Reply

Your email address will not be published. Required fields are marked *