Available on Maven Central.
<dependency>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>2.2.0</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.
This plugin is designed to be light, fast and with minimum dependencies (only those required by Maven).
- 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>
If the property composeFiles
which allows multiple compose files is present then the value of this composeFile
property is ignored.
composeFiles
- Location of multiple compose files. If this property is present then the value of the composeFile
is ignored.
This can be configured in the configuration section of the plugin:
<configuration>
<composeFiles>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<composeFile>${project.basedir}/docker-compose.override.yml</composeFile>
</composeFiles>
</configuration>
detachedMode
- Run in detached mode
This adds -d
to the up command.
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
This adds -v
to the down
command.
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>
apiVersion
- Specify compose API version
<configuration>
<apiVersion>1.22</apiVersion>
</configuration>
verbose
- Enable verbose output
<configuration>
<verbose>true</verbose>
</configuration>
skip
- Skip execution
<configuration>
<skip>true</skip>
</configuration>
host
- Specify host
<configuration>
<host>unix:///var/run/docker.sock</host>
</configuration>
build
- Build images before starting containers
This adds --build
to the up
command.
The plugin will not build images first by default.
This can be changed in the configuration section of the plugin:
<configuration>
<build>true</build>
</configuration>
removeOrphans
- Remove containers for services not defined in the Compose file
This adds --remove-orphans
to the down
command.
The plugin will not remove orphans by default.
This can be changed in the configuration section of the plugin:
<configuration>
<removeOrphans>true</removeOrphans>
</configuration>
removeImages
- Remove images when executing down
This adds --rmi
to the down
command.
The plugin will not remove images by default.
This can be changed in the configuration section of the plugin:
<configuration>
<removeImages>true</removeImages>
</configuration>
Additional option removeImagesType
allows to specify type
parameter of --rmi
docker compose flag.
all
is the default value.
local
is the second supported type.
<configuration>
<removeImages>true</removeImages>
<removeImagesType>local</removeImagesType>
</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>2.2.0</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>2.2.0</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