Recently, I have explored on various Docker Maven plugins and used https://github.com/fabric8io/docker-maven-plugin as its somewhat easy. Please note that as of now, this does not have support to integrate with Docker compose file. But it provides a lot of configuration tags by using which we can completely replace all the configurations found in a docker compose file.
Assume that we have two Restful services running on port number 8080, 8081 respectively. Both are entirely different. The first Restful application runs on 8080 access the second Restful application running on port number 8081. Refer below the snippet of pom.xml which uses the docker maven plugin
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.15.1</version>
<configuration>
<images>
<!-- Application 1 -->
<image>
<name>middleware-rest</name>
<alias>middleware-rest</alias>
<build>
<cleanup>true</cleanup>
<tags>
<tag>latest</tag>
</tags>
<ports>
<port>8080</port>
</ports>
<dockerFileDir>middleware-rest</dockerFileDir>
<assembly>
<mode>dir</mode>
<inline xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>middleware-rest</id>
<files>
<file>
<source>${project.build.directory}/mwRest-${project.version}-appjar.jar</source>
<outputDirectory>./</outputDirectory>
<destName>mwRest.jar</destName>
</file>
</files>
</inline>
</assembly>
</build>
<run>
<namingStrategy>none</namingStrategy>
<ports>
<port>8080:8080</port>
</ports>
<wait>
<tcp>
<ports>
<port>8080</port>
</ports>
</tcp>
<time>60000</time>
</wait>
<env>
<CLIENT_MW_URL>http://client-middleware-rest:8080</CLIENT_MW_URL>
</env>
<links>
<link>client-middleware-rest:client-middleware-rest</link>
</links>
<log>
<enabled>true</enabled>
<color>red</color>
<driver>
<name>json-file</name>
<opts>
<max-size>10m</max-size>
<max-file>5</max-file>
</opts>
</driver>
</log>
</run>
</image>
<!-- Application 2 -->
<image>
<name>client-middleware-rest</name>
<alias>client-middleware-rest</alias>
<build>
<cleanup>true</cleanup>
<tags>
<tag>latest</tag>
</tags>
<ports>
<port>8081</port>
</ports>
<dockerFileDir>client-middleware-rest</dockerFileDir>
<assembly>
<mode>dir</mode>
<inline xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>client-middleware-rest</id>
<files>
<file>
<source>${project.build.directory}/clientmwRest-${project.version}-appjar.jar</source>
<outputDirectory>./</outputDirectory>
<destName>clientmwRest.jar</destName>
</file>
</files>
</inline>
</assembly>
</build>
<run>
<namingStrategy>none</namingStrategy>
<ports>
<port>8081:8081</port>
</ports>
<wait>
<tcp>
<ports>
<port>8081</port>
</ports>
</tcp>
<time>60000</time>
</wait>
<log>
<enabled>true</enabled>
<color>red</color>
<driver>
<name>json-file</name>
<opts>
<max-size>10m</max-size>
<max-file>5</max-file>
</opts>
</driver>
</log>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>remove</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>remove</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
So once you have this configuration, then we can build the containers by running mvn docker:build
To start all the containers, run mvn docker:start
To stop all the containets, run mvn docker:remove
For further information, Please access https://github.com/fabric8io/docker-maven-plugin
Also refer my other post to know more about this Rest API to produce message to Kafka using Docker Maven Plugin