question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin fails to start docker comtainer when multiple maven profiles are executed

See original GitHub issue

In my maven project, I have multiple maven profiles. In each profile, I have docker-maven-plugin and maven-failsafe-plugin. I have profiles for each database type (i.e. MySQL, Postgres etc.). What I’m trying to do is that run my integration tests on docker for each database type.

       <profile>
            <id>local-mysql</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.18.1</version>
                        <executions>
                            <execution>
                                <id>start-docker-for-mysql</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-docker-for-mysql</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <images>
                                <image>
                                    <alias>apim-mysql</alias>
                                    <name>mysql:5.7</name>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <env>
                                            <MYSQL_DATABASE>testamdb</MYSQL_DATABASE>
                                            <MYSQL_ROOT_PASSWORD>root</MYSQL_ROOT_PASSWORD>
                                        </env>
                                        <wait>
                                            <tcp>
                                                <ports>
                                                    <port>3306</port>
                                                </ports>
                                            </tcp>
                                            <time>60000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.19.1</version>
                        <executions>
                            <execution>
                                <id>integration-test-for-mysql</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify-for-mysql</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>local-postgres</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.18.1</version>
                        <executions>
                            <execution>
                                <id>start-docker-for-postgres</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-docker-for-postgres</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <images>
                                <image>
                                    <alias>apim-postgres</alias>
                                    <name>postgres:9.6-alpine</name>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <env>
                                            <POSTGRES_PASSWORD>root</POSTGRES_PASSWORD>
                                            <POSTGRES_USER>root</POSTGRES_USER>
                                            <POSTGRES_DB>testamdb</POSTGRES_DB>
                                        </env>
                                        <wait>
                                            <tcp>
                                                <ports>
                                                    <port>5432</port>
                                                </ports>
                                            </tcp>
                                            <time>60000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.19.1</version>
                        <executions>
                            <execution>
                                <id>integration-test-for-postgres</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify-for-postgres</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

However, when I run this command,

mvn clean install -P local-mysql,local-postgres

it fails with below error.

[INFO] --- docker-maven-plugin:0.18.1:start (start-docker-for-mysql) @ org.wso2.carbon.apimgt.core ---
[INFO] DOCKER> [postgres:9.6-alpine] "apim-postgres": Start container afdf04e8a129
[INFO] DOCKER> [postgres:9.6-alpine] "apim-postgres": Waiting for ports [5432] directly on container with IP (172.17.0.2).
[INFO] DOCKER> [postgres:9.6-alpine] "apim-postgres": Waited on tcp port '[/172.17.0.2:5432]' 4006 ms
[INFO] 
[INFO] --- docker-maven-plugin:0.18.1:start (start-docker-for-postgres) @ org.wso2.carbon.apimgt.core ---
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[INFO] DOCKER> [postgres:9.6-alpine] "apim-postgres": Stop and removed container afdf04e8a129 after 0 ms
[ERROR] DOCKER> I/O Error
[INFO] ------------------------------------------------------------------------

If you look clearly, it starts Postgres container at start-docker-for-MySQL execution, which is wrong. And it fails when it tries to start Postgres container again in start-docker-for-Postgres execution which makes sense, due to the previous issue.

I believe this is a bug. If not, please let me know what I’m doing wrong.

  • d-m-p version: 0.18.1
  • Maven version (mvn -v) : 3.3.9
  • Docker version : 1.12.1

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
seckinsqcommented, Dec 20, 2018

thanks @bhathiya for sharing. mine was a bit simpler, so I gave up and run all images. And disable/enable tests that use that additional image. The image that I wanted to add with certain profile was a small one. If I need more then I will certainly use your solution. Thanks again.

0reactions
bhathiyacommented, Dec 20, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

maven - Run a goal of a plugin inside a profile - Stack Overflow
You get an error on invoking the exec goal of the the exec-maven-plugin because its configuration (the one you meant) is part of...
Read more >
Using Docker from Maven and Maven from Docker - Codefresh
This means that the Docker version that is injected in the Maven lifecycle is always the same as the Docker daemon that will...
Read more >
Guide to Maven Profiles - Baeldung
Next, we'll execute the profile by running the mvn package -Pno-tests command. Now the artifact is created and the tests are skipped.
Read more >
fabric8io/docker-maven-plugin
This is a Maven plugin for managing Docker images and containers. ... With this plugin it is possible to run completely isolated integration ......
Read more >
Using profiles with Compose - Docker Documentation
Multiple profiles can be specified by passing multiple --profile flags or a ... will only start backend and db $ docker compose up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found