Available on Maven Central.
<dependency>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>1.0.1</version>
</dependency>
Maven plugin for running basic docker-compose
commands with Maven.
This can be used as part of the Maven lifecycle or as a utility to bring docker-compose
commands to your Maven toolkit.
- up - runs
docker-compose up
- down - runs
docker-compose down
composeFile
- Location of the compose file e.g. ${project.basedir}/docker-compose.yml
The Plugin assumes your docker file is in ${project.basedir}/src/main/resources/docker-compose.yml
This can be changed in the configuration section of the plugin:
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
</configuration>
detachedMode
- Run in detached mode e.g. docker-compose up -d
The plugin will not run in detached mode by default.
This can be changed in the configuration section of the plugin:
<configuration>
<detachedMode>true</detachedMode>
</configuration>
removeVolumes
- Delete volumes e.g. docker-compose down -v
The plugin will not remove any volumes you create when using the down
goal.
This can be changed in the configuration section of the plugin:
<configuration>
<removeVolumes>true</removeVolumes>
</configuration>
Below will allow use of the plugin from the mvn
command line:
<build>
<plugins>
<plugin>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>1.0.1</version>
</plugin>
</plugins>
</build>
This assumes the compose file is in the default location and will not run in any phase of the build.
Below has customised the location of the docker-compose.yml
file and has two executions defined:
<build>
<plugins>
<plugin>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>up</id>
<phase>verify</phase>
<goals>
<goal>up</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>true</detachedMode>
</configuration>
</execution>
<execution>
<id>down</id>
<phase>verify</phase>
<goals>
<goal>down</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<removeVolumes>true</removeVolumes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
This will run the following as part of the verify
phase:
docker-compose up -d
using adocker-compose.yml
file in a custom locationdocker-compose down -v
using adocker-compose.yml
file in a custom location