Reputation: 12405
I have a SpringBoot application which I can run using ./mvnw spring-boot:run
either from CLI or IDE. I have a docker-compose.yml
file which has dependent services like Postgres, Localstack etc.
I want to invoke docker-compose up
before triggering the spring-boot:run
goal automatically using Maven.
With Gradle I can simple use dependsOn
to spin up docker container before running a task.
I couldn't figure out how to tie up this using Maven life cycle phases. Any help?
Upvotes: 1
Views: 1846
Reputation: 494
you can select the folder where the yaml
is located with -f
, and in the modern docker, compose is a plugin part of docker itself, meaning that you run it with docker compose
without the -
. For example:
<configuration>
<executable>docker</executable>
<commandlineArgs>compose -f src/test/docker/docker-compose.yaml up -d</commandlineArgs>
</configuration>
Upvotes: 0
Reputation: 43
I know that this is an old question, but I already had the same question, and I already find the solution. To do this I add the plugin exec-maven-plugin
and executed the docker-compose.yml file with it at validate
phase:
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Run Containers</id>
<phase>validate</phase>
<configuration>
<executable>docker-compose</executable>
<commandlineArgs>up --detach</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
But you need to put the compose file at project's root folder.
Upvotes: 2