Skip to content

Using docker-maven-plugin from two profiles with different ports causes 'port is already allocated' error #1874

Open
@adamretter

Description

@adamretter

Hi there, maybe I am doing something silly, but I can't see it yet. I have a Maven project that uses two profiles, basically I want to run tests against two different versions of a database (which is a Docker Image). Each profile tries to start the database Docker Image using its own distinct port (10096 and 10097 respectively). I have checked that those ports are not already in use on my system. When I run the profiles manually from the command line each works fine, but when run together I get the following error:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.46.0:start (docker-db-api-7-it-start) on project monex: I/O Error: Unable to start container id [0a0eb824aada] : {"message":"failed to set up container networking: driver failed programming external connectivity on endpoint elemental-2 (e63a42680265a7ccc251142192e9b5773e54ec193a3c651878204ecbbd63d4ef): Bind for 0.0.0.0:10097 failed: port is already allocated"} (Internal Server Error: 500) -> [Help 1]

My pom.xml has these significant bits:

<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">

  <profiles>

    <profile>
      <!--
            Starts eXist-db 6.x.x inside Docker and Deploys Monex for the purposes of Integration Testing
      -->
      <id>docker-integration-test-db-api-7</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.46.0</version>
            <configuration>
              <verbose>true</verbose>
              <images>
                <image>
                  <alias>db-api-6-monex-tests</alias>
                  <name>existdb/existdb:6.4.0</name>
                  <run>
                    <ports>
                      <port>10096:8080</port>
                    </ports>
                    <wait>
                      <log>Server has started, listening on</log>
                      <time>120000</time>
                    </wait>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>docker-db-api-6-it-start</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>docker-db-api-6-it-stop</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!--
            Starts Elemental 7.x.x inside Docker and Deploys Monex for the purposes of Integration Testing
      -->
      <id>docker-integration-test-db-api-7</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.46.0</version>
            <configuration>
              <verbose>true</verbose>
              <images>
                <image>
                  <alias>db-api-7-monex-tests</alias>
                  <name>evolvedbinary/elemental:7.1.1-SNAPSHOT</name>
                  <run>
                    <ports>
                      <port>10097:8080</port>
                    </ports>
                    <wait>
                      <log>Server has started, listening on</log>
                      <time>120000</time>
                    </wait>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>docker-db-api-7-it-start</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>docker-db-api-7-it-stop</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>
</project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions