Docker-maven-plugin: docker:start wait on tcp port always failing

Created on 29 Jun 2019  路  7Comments  路  Source: fabric8io/docker-maven-plugin

Description

Using below configuration:

<?xml version="1.0"?>
<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>me.chanjar</groupId>
  <artifactId>dmp-test</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.30.0</version>
        <configuration>
          <images>
            <image>
              <name>postgres</name>
              <alias>postgres</alias>
              <run>
                <env>
                  <POSTGRES_DB>saga</POSTGRES_DB>
                  <POSTGRES_USER>saga</POSTGRES_USER>
                  <POSTGRES_PASSWORD>password</POSTGRES_PASSWORD>
                </env>
                <wait>
                  <log>database system is ready to accept connections</log>
                  <tcp>
                    <ports>
                      <port>5432</port>
                    </ports>
                  </tcp>
                  <time>60000</time>
                </wait>
                <ports>
                  <port>postgres.port:5432</port>
                </ports>
              </run>
            </image>
          </images>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

mvn docker:start got error:

[INFO] DOCKER> [postgres:latest] "postgres": Start container b76c2d9ed4cc
[INFO] DOCKER> [postgres:latest] "postgres": Network mode: default
[INFO] DOCKER> [postgres:latest] "postgres": Waiting for ports [5432] directly on container with IP (null).
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[INFO] DOCKER> Pattern 'database system is ready to accept connections' matched for container b76c2d9ed4cc
[INFO] DOCKER> [postgres:latest] "postgres": Stop and removed container b76c2d9ed4cc after 0 ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.610 s
[INFO] Finished at: 2019-06-29T03:07:40Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.30.0:start (default-cli) on project dmp-test: Execution default-cli of goal io.fabric8:docker-maven-plugin:0.30.0:start failed: hostname can't be null -> [Help 1]

If downgrade d-m-p to 0.28.0 everything goes fine.

Info

  • d-m-p version : 0.30.0
  • Maven version (mvn -v) :
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /home/ubuntu/maven
Java version: 1.8.0_212, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-52-generic", arch: "amd64", family: "unix"
  • Docker version : 18.09.6

Most helpful comment

Hi,
It take me all morning figuring out how to solve this issue.
Finally the solution I鈥檝e found is to change the tcp mode in my configuration to mapped.
However I鈥檓 on the 0.29.0 version and not sure it will work on the latest.
Also, I鈥檓 still thinking there鈥檚 a bug here and my solution is more of a hack than a real way to solve this issue.

All 7 comments

Hi,
It take me all morning figuring out how to solve this issue.
Finally the solution I鈥檝e found is to change the tcp mode in my configuration to mapped.
However I鈥檓 on the 0.29.0 version and not sure it will work on the latest.
Also, I鈥檓 still thinking there鈥檚 a bug here and my solution is more of a hack than a real way to solve this issue.

Found a potentially better fix.

The problem is with:
https://github.com/fabric8io/docker-maven-plugin/blob/5541e175cba29424b9a7ac6791d3f995a587a3dd/src/main/java/io/fabric8/maven/docker/service/WaitService.java#L179

If the network mode on the image is not set, it acts as the default, which is bridge. However, the actual string networkMode is "default", not "bridge", so it doesn't fall into the right block to get the right hostname/ip.

So fix for now is to explicitly set the network mode to bridge in your image.

I hit this issue with 0.31.0 today.
It looks like we need to release new version of docker plugin to pick up the fix.

@WillemJiang could you try with the latest snapshot release ? I just pushed a 0.31-SNAPSHOT to Maven central.

I'm planning a release for the weekend, so would be good to know if the issue here would be fixed with it.

@rhuss I just ran the test with the 0.31-SNAPSHOT(by building the source on my box, as I didn't find the snapshot link from maven central), the test passed on my project without any issue.
I'm looking forward to the new release.

This is still happening to me on 0.31 as well as 0.33

Same for me on 0.34, on a mac. Network is specified as bridge.

Most probably related to this: https://docs.docker.com/docker-for-mac/networking/#there-is-no-docker0-bridge-on-macos

Very new to macOS, still digging

Was this page helpful?
0 / 5 - 0 ratings