I am trying to run docker compose using mvn clean install, but it doesn't return log. the problem is if I don't set the detachedMode = true, it shows the log of containers but it will remain in up state and the down goal doesn't run. On the other hand, if I don't set detachedMode, it doesn't show any logs from container. Is there any way if I can tail the docker container logs in maven? also I have two services, one is postgresql and the other is flyway, if any of those one failed, mvn clean install will be run successfully and don't return failure. How can I force maven to fail if there is any error in any of the containers?
Here is my docker
version: '3'
services:
flyway:
image: flyway/flyway:latest
command: -configFiles=/flyway/conf/flyway.config -locations=filesystem:/flyway/sql -connectRetries=60 migrate
volumes:
- ~/flyway/sql:/flyway/sql
- ~/flyway/conf/flyway1.config:/flyway/conf/flyway.config
depends_on:
postgres:
condition: service_healthy
links:
- postgres
postgres:
image: postgres:13.8-alpine
restart: always
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=p0stgr3sql13
- POSTGRES_DB=postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 10s
timeout: 3s
retries: 3
and here is my pom.xml:
<plugin>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>true</detachedMode>
<log> default </log>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>docker-compose-up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>up</goal>
</goals>
</execution>
<execution>
<id>docker-compose-down</id>
<phase>post-integration-test</phase>
<goals>
<goal>down</goal>
</goals>
</execution>
</executions>
</plugin>