fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 643 forks source link

Cannot resolve image dependencies for start order when starting containers in different lifecycle phases #1476

Open ewencluley opened 3 years ago

ewencluley commented 3 years ago

Description

Containers started in different parts of the maven lifecycle cannot be linked.

Given a simple configuration where a container is started in one lifecycle phase and then another is started in another lifecycle phase that has a dependency on the first- e.g.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>1</version>
    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.35.0</version>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <images>
                                <image>
                                    <alias>container1</alias>
                                    <name>ubuntu:latest</name>
                                    <run/>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <images>
                                <image>
                                    <alias>container2</alias>
                                    <name>ubuntu:latest</name>
                                    <run>
                                        <links>
                                            <link>container1</link>
                                        </links>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

When running mvn clean integration-test (i.e. the later lifecycle phase with the dependent container) Then docker maven plugin will exit with error

[INFO] --- docker-maven-plugin:0.35.0:start (pre-integration-test) @ test ---
[INFO] DOCKER> [ubuntu:latest] "container1": Start container c29a447b3dc4
[INFO] 
[INFO] --- docker-maven-plugin:0.35.0:start (integration-test) @ test ---
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[INFO] DOCKER> [ubuntu:latest] "container1": Stop and removed container c29a447b3dc4 after 0 ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.313 s
[INFO] Finished at: 2021-05-27T13:46:03+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.35.0:start (test) on project test: Execution test of goal io.fabric8:docker-maven-plugin:0.35.0:start failed: Cannot resolve image dependencies for start order
[ERROR] Unresolved images:
[ERROR] * container2 depends on container1

I have tried this with other images with the same results.

It's possible I have missed something in the config but I think this should not happen given this resolved issue https://github.com/fabric8io/docker-maven-plugin/issues/195

Info

ewencluley commented 3 years ago

I have worked out that if I specify a custom network this works and the containers started in different phases can now communicate.

Is this the expected behaviour?

rhuss commented 3 years ago

sorry for the late answer, and happy that it worked out for you. I'm currently not deep in the plugin anymore so can't really say whether this is expected or not :)