Docker cp maven package into running container by maven

54 Views Asked by At

For local development I'd like to copy a maven war package into a docker container right after mvn package has created the package. How can I accomplish this?

My workflow as of right now is with a specific dockerid:

$ mvn clean package
$ docker cp the.war dockerid:/usr/local/tomcat/webapps/the.war

A Tomcat server in the docker container recognizes the new war and starts again.

I tried adding the maven-antrun-plugin. However, the war is not deployed, whether I use it in the install or package phase. I get no error or warning with e.g. mvn clean package. However, the.war file is not copied into the docker container.

Below the dockerid is hardcoded momentarily.

   <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.jdk>1.8</version.jdk>
        <version.maven.compiler>3.6.1</version.maven.compiler>
   ...
   </properties>
...
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>3.1.0</version>
        </dependency>
...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <exec executable="docker">
                                    <arg value="cp"/>
                                    <arg value="${basedir}/target/the.war"/>
                                    <arg value="dockerid:/usr/local/tomcat/webapps/the.war"/>
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
0

There are 0 best solutions below